Asked  7 Months ago    Answers:  5   Viewed   39 times

In Visual C++, it's possible to use #pragma warning (disable: ...). Also I found that in GCC you can override per file compiler flags. How can I do this for "next line", or with push/pop semantics around areas of code using GCC?

 Answers

79

It appears this can be done. I'm unable to determine the version of GCC that it was added, but it was sometime before June 2010.

Here's an example:

#pragma GCC diagnostic error "-Wuninitialized"
    foo(a);         /* error is given for this one */
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wuninitialized"
    foo(b);         /* no diagnostic for this one */
#pragma GCC diagnostic pop
    foo(c);         /* error is given for this one */
#pragma GCC diagnostic pop
    foo(d);         /* depends on command line options */
Tuesday, June 1, 2021
 
Blacksonic
answered 7 Months ago
11

Since version 13 it's possible to wrap the code with

// @formatter:off
...
// @formatter:on 

IntelliJ IDEA v.2018+:

File > Settings > Editor > Code Style

IntelliJ IDEA v.2016+:

Preferences > Editor > Code Style

IntelliJ IDEA v.14+:

Preferences > Editor > Code Style > Formatter Control

You can change the formatter control markers, as long as they're in comments.


Ensure formatter markers in comments are enabled, as shown in the following figure:

Formatter Control Preference

Wednesday, June 2, 2021
 
Avicinnian
answered 7 Months ago
27

This is possible in GCC since version 4.6, or around June 2010 in the trunk.

Here's an example:

#pragma GCC diagnostic push
#pragma GCC diagnostic error "-Wuninitialized"
    foo(a);         /* error is given for this one */
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wuninitialized"
    foo(b);         /* no diagnostic for this one */
#pragma GCC diagnostic pop
    foo(c);         /* error is given for this one */
#pragma GCC diagnostic pop
    foo(d);         /* depends on command line options */
Friday, June 4, 2021
 
DaveRandom
answered 7 Months ago
85

I got the answer. :-) Those cascade deletes were being created because of ManyToManyCascadeDeleteConvention. You need to remove this convention to prevent it from creating cascade deletes for link tables:

modelBuilder.Conventions.Remove<ManyToManyCascadeDeleteConvention>();
Thursday, June 10, 2021
 
michele
answered 7 Months ago
13

After one year I revised the issue:

Just tested again with different compiler versions. When I first ran into this bug (now I am quite sure, I am allowed to call it a bug), I already realized the warning existed only in clang < 3.1 and all GCC versions at that time. The warning is still produced by all GCC versions < 5.

Since there is no other way to silence the error, the only solution is to update to GCC > 5 or add the unsigned cast a.flag = (unsigned)b.flag | c.flag;.

Wednesday, November 3, 2021
 
xenon
answered 1 Month ago
Only authorized users can answer the question. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :
 
Share