https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105370
Bug ID: 105370 Summary: Improved diagnostics for code from statement expressions documentation [C++ component] Product: gcc Version: 12.0 Status: UNCONFIRMED Keywords: diagnostic, documentation Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: egallager at gcc dot gnu.org Target Milestone: --- This is the C++ counterpart to bug 105369. Code is taken from GCC documentation on Statement Expressions here: https://gcc.gnu.org/onlinedocs/gcc/Statement-Exprs.html#Statement-Exprs Testcase: $ cat stmt_exprsxx.cc class A { public: int Foo(void); }; int decay(void) { A a; return ({a;}).Foo(); } #define X decay #define macro(a) ({__typeof__(a) b = (a); b + 3; }) template<typename T> T function(T a) { T b = a; return b + 3; } void foobar() { macro(X()); function(X()); } $ The documentation says that there might be surprising behavior about temporaries and construction and destruction, which lead the documentation to the conclusion that "[t]hese considerations mean that it is probably a bad idea to use statement expressions of this form in header files that are designed to work with C++." Perhaps there should be some warning about this (current code doesn't print any warnings with -Wall -Wextra -Weffc++ -pedantic).