Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

trying to silence -Waggregate-return only in a macro for g++ - buggy compiler?

using g++ and compiling with -Waggregate-return

#define DOCTEST_CHECK(expr)                                      \
    do {                                                         \
        _Pragma("GCC diagnostic push");                          \
        _Pragma("GCC diagnostic ignored \"-Waggregate-return\"");\
        if(Result failed = (ExpressionDecomposer() << expr))     \
            printf("%s\n", failed.m_decomposition.c_str());      \
        _Pragma("GCC diagnostic pop");                           \
    } while(false)

DOCTEST_CHECK(true == false); // produces warnings

but the unrolled by hand version does not produce any warnings:

do {                                                                                           
    _Pragma("GCC diagnostic push");                                                            
    _Pragma("GCC diagnostic ignored \"-Waggregate-return\"");                                  
    if(Result failed = (ExpressionDecomposer() << true == false))     
        printf("%s\n", failed.m_decomposition.c_str());                                        
    _Pragma("GCC diagnostic pop");                                                             
} while(false);

Shouldn't the behavior be the same?

I don't think the Result and ExpressionDecomposer types matter - just classes.

I'm trying to get expression decomposition working like here (things have been renamed a bit).

EDIT: >> here << is a live demo of the problem using the lest library

My question is: why? how can I be warning free in the first case using the macro? I cannot afford silencing the warning globally.

like image 968
onqtam Avatar asked Nov 20 '22 12:11

onqtam


1 Answers

These bugs look relevant:

  • https://gcc.gnu.org/bugzilla/show_bug.cgi?id=55578
  • https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69543

So it might have to do with line number comparisons, or some similar issue within the parser, and it might be fixed in some future version.

like image 129
rici Avatar answered Dec 05 '22 10:12

rici