From a4abe51864f1d9adde75bb0c944a05ab88d36f13 Mon Sep 17 00:00:00 2001 From: ville Date: Thu, 24 May 2018 19:05:46 +0000 Subject: [PATCH] Pedwarn on a non-standard position of a C++ attribute. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@260682 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/cp/ChangeLog | 6 ++++++ gcc/cp/parser.c | 5 +++++ gcc/testsuite/g++.dg/cpp0x/gen-attrs-56.C | 2 +- gcc/testsuite/g++.dg/cpp0x/gen-attrs-64.C | 2 +- gcc/testsuite/g++.dg/cpp1z/namespace-attribs2.C | 7 +++++++ 5 files changed, 20 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/g++.dg/cpp1z/namespace-attribs2.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 10e57ee123f..fdf73d182eb 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,9 @@ +2018-05-24 Ville Voutilainen + + Pedwarn on a non-standard position of a C++ attribute. + * parser.c (cp_parser_namespace_definition): Pedwarn about attributes + after the namespace name. + 2018-05-24 Paolo Carlini * cp-tree.h (INDIRECT_TYPE_P): New. diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index c0220bf1bec..f5a6d940601 100644 --- a/gcc/cp/parser.c +++ b/gcc/cp/parser.c @@ -18656,6 +18656,11 @@ cp_parser_namespace_definition (cp_parser* parser) { identifier = cp_parser_identifier (parser); + if (cp_next_tokens_can_be_std_attribute_p (parser)) + pedwarn (input_location, OPT_Wpedantic, + "standard attributes on namespaces must precede " + "the namespace name"); + /* Parse any attributes specified after the identifier. */ attribs = attr_chainon (attribs, cp_parser_attributes_opt (parser)); } diff --git a/gcc/testsuite/g++.dg/cpp0x/gen-attrs-56.C b/gcc/testsuite/g++.dg/cpp0x/gen-attrs-56.C index f331ed369ac..f63fff4db5e 100644 --- a/gcc/testsuite/g++.dg/cpp0x/gen-attrs-56.C +++ b/gcc/testsuite/g++.dg/cpp0x/gen-attrs-56.C @@ -2,4 +2,4 @@ // { dg-do compile { target c++11 } } namespace foo __attribute__((visibility("default"))) {} -namespace bar [[gnu::visibility("default")]] {} +namespace [[gnu::visibility("default")]] bar {} diff --git a/gcc/testsuite/g++.dg/cpp0x/gen-attrs-64.C b/gcc/testsuite/g++.dg/cpp0x/gen-attrs-64.C index c0d48fc88e9..4b335eb2818 100644 --- a/gcc/testsuite/g++.dg/cpp0x/gen-attrs-64.C +++ b/gcc/testsuite/g++.dg/cpp0x/gen-attrs-64.C @@ -1,4 +1,4 @@ // PR c++/85140 // { dg-do compile { target c++11 } } -namespace N alignas() {} // { dg-error "expected" } +namespace alignas() N {} // { dg-error "expected" } diff --git a/gcc/testsuite/g++.dg/cpp1z/namespace-attribs2.C b/gcc/testsuite/g++.dg/cpp1z/namespace-attribs2.C new file mode 100644 index 00000000000..2049da33ab5 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp1z/namespace-attribs2.C @@ -0,0 +1,7 @@ +// { dg-options "-std=c++17" } +// { dg-additional-options "-pedantic" } + +namespace B [[deprecated]] {} // { dg-warning "ignored|must precede" } + +namespace [[deprecated]] D {} // { dg-warning "ignored" } + -- 2.11.4.GIT