On 9/3/24 7:00 PM, Andrew Pinski wrote:
On Tue, Sep 3, 2024 at 3:01 PM Jason Merrill <ja...@redhat.com> wrote:
Tested x86_64-pc-linux-gnu, applying to trunk.
-- 8< --
I don't see any reason why we can't allow the [[]] attribute syntax in C++98
mode with a pedwarn just like many other C++11 features. In fact, we
already do support it in some places in the grammar, but not in places that
check cp_nth_tokens_can_be_std_attribute_p.
Let's also follow the C front-end's lead in only warning about them when
-pedantic.
It still isn't necessary for this function to guard against Objective-C
message passing syntax; we handle that with tentative parsing in
cp_parser_statement, and we don't call this function in that context anyway.
gcc/cp/ChangeLog:
* parser.cc (cp_nth_tokens_can_be_std_attribute_p): Don't check
cxx_dialect.
* error.cc (maybe_warn_cpp0x): Only complain about C++11 attributes
if pedantic.
gcc/testsuite/ChangeLog:
* g++.dg/cpp0x/gen-attrs-1.C: Also run in C++98 mode.
* g++.dg/cpp0x/gen-attrs-11.C: Likewise.
* g++.dg/cpp0x/gen-attrs-13.C: Likewise.
* g++.dg/cpp0x/gen-attrs-15.C: Likewise.
* g++.dg/cpp0x/gen-attrs-75.C: Don't expect C++98 warning after
__extension__.
---
gcc/cp/error.cc | 7 ++++---
gcc/cp/parser.cc | 9 ++++-----
gcc/testsuite/g++.dg/cpp0x/gen-attrs-1.C | 2 +-
gcc/testsuite/g++.dg/cpp0x/gen-attrs-11.C | 2 +-
gcc/testsuite/g++.dg/cpp0x/gen-attrs-13.C | 2 +-
gcc/testsuite/g++.dg/cpp0x/gen-attrs-15.C | 2 +-
gcc/testsuite/g++.dg/cpp0x/gen-attrs-75.C | 10 +++++-----
7 files changed, 17 insertions(+), 17 deletions(-)
diff --git a/gcc/cp/error.cc b/gcc/cp/error.cc
index 57cd76caf49..4a9e9aa3cdc 100644
--- a/gcc/cp/error.cc
+++ b/gcc/cp/error.cc
@@ -4735,9 +4735,10 @@ maybe_warn_cpp0x (cpp0x_warn_str str, location_t
loc/*=input_location*/)
"only available with %<-std=c++11%> or %<-std=gnu++11%>");
break;
case CPP0X_ATTRIBUTES:
- pedwarn (loc, OPT_Wc__11_extensions,
- "C++11 attributes "
- "only available with %<-std=c++11%> or %<-std=gnu++11%>");
+ if (pedantic)
+ pedwarn (loc, OPT_Wc__11_extensions,
+ "C++11 attributes "
+ "only available with %<-std=c++11%> or %<-std=gnu++11%>");
Shouldn't the warning also change to mention -std=gnu++98 now? Or
maybe reworded a little more?
That's the conventional wording for pedwarns about extensions from later
standards; I wouldn't change this one alone, though I agree a general
rewording might make sense.
Jason