From patchwork Sun Sep 20 21:22:02 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Ville Voutilainen X-Patchwork-Id: 520056 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id E79571401CD for ; Mon, 21 Sep 2015 07:22:14 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=HW2vZEjd; dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :mime-version:in-reply-to:references:date:message-id:subject :from:to:content-type; q=dns; s=default; b=TjTdimuNtOS+OrBoAoLeK BPYAqPC9IjsStISdhfU3gRLpsT1+uN5trHqOEnypUyexzUNS9Y51uFoB50V4qZ9r oB5iZigL58RaV2U+NDuMvzYhe7HJAEB0nHTfCsMja0G6kOw0GE00CMDIATVfwKoF zMszD6pfJWiSFOCLun5zI0= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :mime-version:in-reply-to:references:date:message-id:subject :from:to:content-type; s=default; bh=4WiHgYhyILcNTrU89y22HLoLb68 =; b=HW2vZEjdTWgZkABtCEqwfX43zdgMfIIxmoLymscqL8tTY2otrovunxyHe0I kDJMRNmvX6XzWZfd0b91e7HfsS9C6Fyp/MZSAwvEciVykXqY8aN+QB75c2T3FvIE 94vS1GyX4KpBAx3tjuduVjA13KT6thUMlMYslG5CPnsxhFEE= Received: (qmail 98676 invoked by alias); 20 Sep 2015 21:22:07 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 98666 invoked by uid 89); 20 Sep 2015 21:22:06 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.6 required=5.0 tests=AWL, BAYES_00, FREEMAIL_FROM, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.2 X-HELO: mail-vk0-f45.google.com Received: from mail-vk0-f45.google.com (HELO mail-vk0-f45.google.com) (209.85.213.45) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Sun, 20 Sep 2015 21:22:04 +0000 Received: by vkfp126 with SMTP id p126so54954267vkf.3 for ; Sun, 20 Sep 2015 14:22:02 -0700 (PDT) MIME-Version: 1.0 X-Received: by 10.31.2.193 with SMTP id 184mr9450764vkc.126.1442784122522; Sun, 20 Sep 2015 14:22:02 -0700 (PDT) Received: by 10.103.37.195 with HTTP; Sun, 20 Sep 2015 14:22:02 -0700 (PDT) In-Reply-To: References: Date: Mon, 21 Sep 2015 00:22:02 +0300 Message-ID: Subject: Re: [C++ PATCH] Complete the implementation of N4230, Nested namespace definition. From: Ville Voutilainen To: "gcc-patches@gcc.gnu.org" , Jason Merrill On 21 September 2015 at 00:08, Ville Voutilainen wrote: > /cp > 2015-09-20 Ville Voutilainen > > Complete the implementation of N4230, Nested namespace definition. > * parser.c (cp_parser_namespace_definition): Support namespace > attributes both before and after the namespace identifier. Boo hiss, this change wasn't looking at the open-square that's supposed to follow the first open-square, I'm finishing testing the attached patch, which looks at cp_lexer_peek_nth_token (parser->lexer, 3)->type instead of cp_lexer_peek_nth_token (parser->lexer, 2)->type which is already token2's type. diff --git a/gcc/c-family/ChangeLog b/gcc/c-family/ChangeLog index b45b53e..c396735 100644 --- a/gcc/c-family/ChangeLog +++ b/gcc/c-family/ChangeLog @@ -1,3 +1,9 @@ +2015-09-20 Ville Voutilainen + + Complete the implementation of N4230, Nested namespace definition. + * c-cppbuiltin.c: Add __cpp_namespace_attributes and + __cpp_nested_namespace_definitions. + 2015-09-18 Manuel López-Ibáñez * c-pragma.c (handle_pragma_diagnostic): Fix wrong return. diff --git a/gcc/c-family/c-cppbuiltin.c b/gcc/c-family/c-cppbuiltin.c index 0e45a57..b222a9f 100644 --- a/gcc/c-family/c-cppbuiltin.c +++ b/gcc/c-family/c-cppbuiltin.c @@ -870,6 +870,8 @@ c_cpp_builtins (cpp_reader *pfile) { /* Set feature test macros for C++1z. */ cpp_define (pfile, "__cpp_static_assert=201411"); + cpp_define (pfile, "__cpp_namespace_attributes=201411"); + cpp_define (pfile, "__cpp_nested_namespace_definitions=201411"); } if (flag_concepts) /* Use a value smaller than the 201507 specified in diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index ab71f92..ed782a6 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,9 @@ +2015-09-20 Ville Voutilainen + + Complete the implementation of N4230, Nested namespace definition. + * parser.c (cp_parser_namespace_definition): Support namespace + attributes both before and after the namespace identifier. + 2015-09-19 Trevor Saunders * cp-gimplify.c (gimplify_must_not_throw_expr): Adjust. diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index 2071276..0134189 100644 --- a/gcc/cp/parser.c +++ b/gcc/cp/parser.c @@ -11645,6 +11645,9 @@ cp_parser_declaration (cp_parser* parser) (token2.type == CPP_NAME && (cp_lexer_peek_nth_token (parser->lexer, 3)->type != CPP_EQ)) + || (token2.type == CPP_OPEN_SQUARE + && cp_lexer_peek_nth_token (parser->lexer, 3)->type + == CPP_OPEN_SQUARE) /* An unnamed namespace definition. */ || token2.type == CPP_OPEN_BRACE || token2.keyword == RID_ATTRIBUTE)) @@ -16969,6 +16972,9 @@ cp_parser_namespace_definition (cp_parser* parser) /* Look for the `namespace' keyword. */ token = cp_parser_require_keyword (parser, RID_NAMESPACE, RT_NAMESPACE); + /* Parse any specified attributes before the identifier. */ + attribs = cp_parser_attributes_opt (parser); + /* Get the name of the namespace. We do not attempt to distinguish between an original-namespace-definition and an extension-namespace-definition at this point. The semantic @@ -16978,8 +16984,15 @@ cp_parser_namespace_definition (cp_parser* parser) else identifier = NULL_TREE; - /* Parse any specified attributes. */ - attribs = cp_parser_attributes_opt (parser); + /* Parse any specified attributes after the identifier. */ + tree post_ident_attribs = cp_parser_attributes_opt (parser); + if (post_ident_attribs) + { + if (attribs) + attribs = chainon (attribs, post_ident_attribs); + else + attribs = post_ident_attribs; + } /* Start the namespace. */ push_namespace (identifier); diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 5fd91c1..10747a9 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,15 @@ +2015-09-20 Ville Voutilainen + + Complete the implementation of N4230, Nested namespace definition. + * g++.dg/cpp1y/feat-cxx11-neg.C: Add tests for C++17 namespace + attributes and nested namespace definitions. + * g++.dg/cpp1y/feat-cxx98-neg.C: Likewise. + * g++.dg/cpp1z/feat-cxx1z.C: Likewise. + * g++.dg/cpp1y/feat-cxx14-neg.C: New. + * g++.dg/cpp1z/namespace-attribs.C: Likewise. + * g++.dg/cpp1z/nested-namespace-def1.C: Add tests for attributes + appearing before the namespace identifier. + 2015-09-20 Oleg Endo * gcc.target/sh/pr43417.c: Move target independent test to ... diff --git a/gcc/testsuite/g++.dg/cpp1y/feat-cxx11-neg.C b/gcc/testsuite/g++.dg/cpp1y/feat-cxx11-neg.C index 81daa04..825d088 100644 --- a/gcc/testsuite/g++.dg/cpp1y/feat-cxx11-neg.C +++ b/gcc/testsuite/g++.dg/cpp1y/feat-cxx11-neg.C @@ -38,6 +38,17 @@ # error "__cpp_sized_deallocation" // { dg-error "error" } #endif +// C++17 features: + +#ifndef __cpp_namespace_attributes +# error "__cpp_namespace_attributes" // { dg-error "error" } +#endif + +#ifndef __cpp_nested_namespace_definitions +# error "__cpp_nested_namespace_definitions" // { dg-error "error" } +#endif + + // Array TS features: #ifndef __cpp_runtime_arrays diff --git a/gcc/testsuite/g++.dg/cpp1y/feat-cxx14-neg.C b/gcc/testsuite/g++.dg/cpp1y/feat-cxx14-neg.C new file mode 100644 index 0000000..221bd3f --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp1y/feat-cxx14-neg.C @@ -0,0 +1,11 @@ +// { dg-do compile { target c++14 } } + +// C++17 features: + +#ifndef __cpp_namespace_attributes +# error "__cpp_namespace_attributes" // { dg-error "error" } +#endif + +#ifndef __cpp_nested_namespace_definitions +# error "__cpp_nested_namespace_definitions" // { dg-error "error" } +#endif diff --git a/gcc/testsuite/g++.dg/cpp1y/feat-cxx98-neg.C b/gcc/testsuite/g++.dg/cpp1y/feat-cxx98-neg.C index 9c25fc3..886b3d3 100644 --- a/gcc/testsuite/g++.dg/cpp1y/feat-cxx98-neg.C +++ b/gcc/testsuite/g++.dg/cpp1y/feat-cxx98-neg.C @@ -113,6 +113,16 @@ # error "__cpp_sized_deallocation" // { dg-error "error" } #endif +// C++17 features: + +#ifndef __cpp_namespace_attributes +# error "__cpp_namespace_attributes" // { dg-error "error" } +#endif + +#ifndef __cpp_nested_namespace_definitions +# error "__cpp_nested_namespace_definitions" // { dg-error "error" } +#endif + // C++11 attributes: #ifdef __has_cpp_attribute diff --git a/gcc/testsuite/g++.dg/cpp1z/feat-cxx1z.C b/gcc/testsuite/g++.dg/cpp1z/feat-cxx1z.C index b3e742c..ead1665 100644 --- a/gcc/testsuite/g++.dg/cpp1z/feat-cxx1z.C +++ b/gcc/testsuite/g++.dg/cpp1z/feat-cxx1z.C @@ -6,3 +6,15 @@ #elif __cpp_static_assert != 201411 # error "__cpp_static_assert != 201411" #endif + +#ifndef __cpp_namespace_attributes +# error "__cpp_namespace_attributes" +#elif __cpp_namespace_attributes != 201411 +# error "__cpp_namespace_attributes != 201411" +#endif + +#ifndef __cpp_nested_namespace_definitions +# error "__cpp_nested_namespace_definitions" +#elif __cpp_nested_namespace_definitions != 201411 +# error "__cpp_nested_namespace_definitions != 201411" +#endif diff --git a/gcc/testsuite/g++.dg/cpp1z/namespace-attribs.C b/gcc/testsuite/g++.dg/cpp1z/namespace-attribs.C new file mode 100644 index 0000000..7dc2173 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp1z/namespace-attribs.C @@ -0,0 +1,10 @@ +// { dg-options "-std=c++1z" } + +namespace A __attribute ((visibility ("default"))) {} + +namespace B [[deprecated]] {} // { dg-warning "ignored" } + +namespace __attribute ((visibility ("default"))) C {} + +namespace [[deprecated]] D {} // { dg-warning "ignored" } + diff --git a/gcc/testsuite/g++.dg/cpp1z/nested-namespace-def1.C b/gcc/testsuite/g++.dg/cpp1z/nested-namespace-def1.C index ebdb70b..3980174 100644 --- a/gcc/testsuite/g++.dg/cpp1z/nested-namespace-def1.C +++ b/gcc/testsuite/g++.dg/cpp1z/nested-namespace-def1.C @@ -17,3 +17,7 @@ namespace G __attribute ((visibility ("default"))) ::H {} // { dg-error "cannot namespace H [[deprecated]] ::I {} // { dg-error "cannot have attributes|ignored" } +namespace __attribute ((visibility ("default"))) I::J {} // { dg-error "cannot have attributes" } + +namespace [[deprecated]] J::K {} // { dg-error "cannot have attributes|ignored" } +