Trying to silence -Waggregate-return only in a macro for a g ++ -computer 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 manually deployed version does not generate 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); 

Should the behavior be the same?

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

I am trying to get a decomposition expression that works like this (things have been renamed).

EDIT: β†’ here <is a live demonstration of the problem using the lest library

My question is why? how can I be a warning for free in the first case using a macro? I cannot afford to silence a warning globally.

+5
source share
2 answers

These errors look relevant:

Thus, this may be due to matching line numbers or a similar problem in the parser, and this may be fixed in some future version.

+1
source

You can try:

 #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) 
-2
source

Source: https://habr.com/ru/post/1244526/


All Articles