From: Nathaniel Shead Date: Fri, 20 Dec 2024 11:09:39 +0000 (+1100) Subject: c++: Allow pragmas in NSDMIs [PR118147] X-Git-Tag: releases/gcc-12.5.0~347 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9d2f4c8b0f849839ff1b9b7d5f9e734271c03634;p=thirdparty%2Fgcc.git c++: Allow pragmas in NSDMIs [PR118147] This patch removes the (unnecessary) CPP_PRAGMA_EOL case from cp_parser_cache_defarg, which currently has the result that any pragmas in the NSDMI cause an error. PR c++/118147 gcc/cp/ChangeLog: * parser.cc (cp_parser_cache_defarg): Don't error when CPP_PRAGMA_EOL. gcc/testsuite/ChangeLog: * g++.dg/cpp0x/nsdmi-defer7.C: New test. Signed-off-by: Nathaniel Shead (cherry picked from commit f3ccc57e5f044031a1b07e79330de9220e93afe7) --- diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc index 9c1bd32cff1c..64cefb6b4e40 100644 --- a/gcc/cp/parser.cc +++ b/gcc/cp/parser.cc @@ -34110,7 +34110,6 @@ cp_parser_cache_defarg (cp_parser *parser, bool nsdmi) /* If we run out of tokens, issue an error message. */ case CPP_EOF: - case CPP_PRAGMA_EOL: error_at (token->location, "file ends in default argument"); return error_mark_node; diff --git a/gcc/testsuite/g++.dg/cpp0x/nsdmi-defer7.C b/gcc/testsuite/g++.dg/cpp0x/nsdmi-defer7.C new file mode 100644 index 000000000000..3bef636ccbd2 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/nsdmi-defer7.C @@ -0,0 +1,13 @@ +// PR c++/118147 +// { dg-do compile { target c++11 } } + +struct F { + int i = []{ + #pragma message "test" // { dg-message "test" } + return 1; + }(); +}; + +struct G { + int i = + #pragma GCC diagnostic push // { dg-error "file ends in default argument|expected" }