From 0d21482100aebb2b53948af330e9f3eb3fe1d9a7 Mon Sep 17 00:00:00 2001 From: Paolo Carlini Date: Thu, 19 Jul 2018 16:58:06 +0000 Subject: [PATCH] revert: [multiple changes] 2018-07-19 Paolo Carlini Revert fix for c++/59480 (and testsuite followup) /testsuite 2018-07-19 Paolo Carlini * g++.old-deja/g++.mike/p784.C: Add -fpermissive. /cp 2019-07-18 Paolo Carlini PR c++/59480, DR 136 * decl.c (check_no_redeclaration_friend_default_args): New. (duplicate_decls): Use the latter; also check that a friend declaration specifying default arguments is a definition. /testsuite 2019-07-18 Paolo Carlini PR c++/59480, DR 136 * g++.dg/other/friend8.C: New. * g++.dg/other/friend9.C: Likewise. * g++.dg/other/friend10.C: Likewise. * g++.dg/other/friend11.C: Likewise. * g++.dg/other/friend12.C: Likewise. * g++.dg/parse/defarg4.C: Compile with -fpermissive -w. * g++.dg/parse/defarg8.C: Likewise. From-SVN: r262883 --- gcc/cp/ChangeLog | 11 ++++ gcc/cp/decl.c | 67 +--------------------- gcc/testsuite/ChangeLog | 19 ++++++ gcc/testsuite/g++.dg/other/friend10.C | 9 --- gcc/testsuite/g++.dg/other/friend11.C | 8 --- gcc/testsuite/g++.dg/other/friend12.C | 11 ---- gcc/testsuite/g++.dg/other/friend8.C | 6 -- gcc/testsuite/g++.dg/other/friend9.C | 9 --- gcc/testsuite/g++.dg/parse/defarg4.C | 2 +- gcc/testsuite/g++.dg/parse/defarg8.C | 2 - gcc/testsuite/g++.old-deja/g++.mike/p784.C | 2 +- 11 files changed, 35 insertions(+), 111 deletions(-) delete mode 100644 gcc/testsuite/g++.dg/other/friend10.C delete mode 100644 gcc/testsuite/g++.dg/other/friend11.C delete mode 100644 gcc/testsuite/g++.dg/other/friend12.C delete mode 100644 gcc/testsuite/g++.dg/other/friend8.C delete mode 100644 gcc/testsuite/g++.dg/other/friend9.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 4a28c839ef3..125f169c167 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,14 @@ +2018-07-19 Paolo Carlini + + Revert fix for c++/59480 (and testsuite followup) + + 2019-07-18 Paolo Carlini + + PR c++/59480, DR 136 + * decl.c (check_no_redeclaration_friend_default_args): New. + (duplicate_decls): Use the latter; also check that a friend + declaration specifying default arguments is a definition. + 2018-07-18 Jakub Jelinek PR c++/86550 diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c index 5239ffd5a07..3c1e2ef3698 100644 --- a/gcc/cp/decl.c +++ b/gcc/cp/decl.c @@ -1280,39 +1280,6 @@ check_redeclaration_no_default_args (tree decl) } } -/* NEWDECL is a redeclaration of a function or function template OLDDECL. - If either the declaration or the redeclaration is a friend declaration - and specifies default arguments issue a diagnostic. Note: this is to - enforce C++17 11.3.6/4: "If a friend declaration specifies a default - argument expression, that declaration... shall be the only declaration - of the function or function template in the translation unit." */ - -static void -check_no_redeclaration_friend_default_args (tree olddecl, tree newdecl) -{ - bool olddecl_friend_p = DECL_FRIEND_P (STRIP_TEMPLATE (olddecl)); - bool newdecl_friend_p = DECL_FRIEND_P (STRIP_TEMPLATE (newdecl)); - - if (!olddecl_friend_p && !newdecl_friend_p) - return; - - tree t1 = FUNCTION_FIRST_USER_PARMTYPE (olddecl); - tree t2 = FUNCTION_FIRST_USER_PARMTYPE (newdecl); - - for (; t1 && t1 != void_list_node; - t1 = TREE_CHAIN (t1), t2 = TREE_CHAIN (t2)) - if ((olddecl_friend_p && TREE_PURPOSE (t1)) - || (newdecl_friend_p && TREE_PURPOSE (t2))) - { - if (permerror (DECL_SOURCE_LOCATION (newdecl), - "friend declaration of %q#D specifies default " - "arguments and isn't the only declaration", newdecl)) - inform (DECL_SOURCE_LOCATION (olddecl), - "previous declaration of %q#D", olddecl); - return; - } -} - /* Merge tree bits that correspond to attributes noreturn, nothrow, const, malloc, and pure from NEWDECL with those of OLDDECL. */ @@ -1909,12 +1876,6 @@ next_arg:; olddecl); } } - - /* C++17 11.3.6/4: "If a friend declaration specifies a default - argument expression, that declaration... shall be the only - declaration of the function or function template in the - translation unit." */ - check_no_redeclaration_friend_default_args (olddecl, newdecl); } } } @@ -2047,18 +2008,11 @@ next_arg:; if (DECL_FUNCTION_TEMPLATE_P (newdecl)) { + /* Per C++11 8.3.6/4, default arguments cannot be added in later + declarations of a function template. */ if (DECL_SOURCE_LOCATION (newdecl) != DECL_SOURCE_LOCATION (olddecl)) - { - /* Per C++11 8.3.6/4, default arguments cannot be added in - later declarations of a function template. */ - check_redeclaration_no_default_args (newdecl); - /* C++17 11.3.6/4: "If a friend declaration specifies a default - argument expression, that declaration... shall be the only - declaration of the function or function template in the - translation unit." */ - check_no_redeclaration_friend_default_args (olddecl, newdecl); - } + check_redeclaration_no_default_args (newdecl); check_default_args (newdecl); @@ -8809,21 +8763,6 @@ grokfndecl (tree ctype, } } - /* C++17 11.3.6/4: "If a friend declaration specifies a default argument - expression, that declaration shall be a definition..." */ - if (friendp && !funcdef_flag) - { - for (tree t = FUNCTION_FIRST_USER_PARMTYPE (decl); - t && t != void_list_node; t = TREE_CHAIN (t)) - if (TREE_PURPOSE (t)) - { - permerror (DECL_SOURCE_LOCATION (decl), - "friend declaration of %qD specifies default " - "arguments and isn't a definition", decl); - break; - } - } - /* If this decl has namespace scope, set that up. */ if (in_namespace) set_decl_namespace (decl, in_namespace, friendp); diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 2555ac0f8aa..f55ecc3454e 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,22 @@ +2018-07-19 Paolo Carlini + + Revert fix for c++/59480 (and testsuite followup) + + 2018-07-19 Paolo Carlini + + * g++.old-deja/g++.mike/p784.C: Add -fpermissive. + + 2019-07-18 Paolo Carlini + + PR c++/59480, DR 136 + * g++.dg/other/friend8.C: New. + * g++.dg/other/friend9.C: Likewise. + * g++.dg/other/friend10.C: Likewise. + * g++.dg/other/friend11.C: Likewise. + * g++.dg/other/friend12.C: Likewise. + * g++.dg/parse/defarg4.C: Compile with -fpermissive -w. + * g++.dg/parse/defarg8.C: Likewise. + 2018-07-19 Andre Vieira * gcc.target/aarch64/profile.c: New test. diff --git a/gcc/testsuite/g++.dg/other/friend10.C b/gcc/testsuite/g++.dg/other/friend10.C deleted file mode 100644 index c162395210b..00000000000 --- a/gcc/testsuite/g++.dg/other/friend10.C +++ /dev/null @@ -1,9 +0,0 @@ -// PR c++/59480 - -class test { - friend int foo(bool = true) { return 1; } // { dg-message "14:previous" } - template friend int bar(bool = true) { return 1; } // { dg-message "33:previous" } -}; - -int foo(bool); // { dg-error "5:friend declaration" } -template int bar(bool); // { dg-error "24:friend declaration" } diff --git a/gcc/testsuite/g++.dg/other/friend11.C b/gcc/testsuite/g++.dg/other/friend11.C deleted file mode 100644 index b82b39ddbe3..00000000000 --- a/gcc/testsuite/g++.dg/other/friend11.C +++ /dev/null @@ -1,8 +0,0 @@ -// PR c++/59480 - -class test { - friend int foo(bool = true) { return 1; } // { dg-message "14:previous" } - friend int foo(bool); // { dg-error "14:friend declaration" } - template friend int bar(bool = true) { return 1; } // { dg-message "33:previous" } - template friend int bar(bool); // { dg-error "33:friend declaration" } -}; diff --git a/gcc/testsuite/g++.dg/other/friend12.C b/gcc/testsuite/g++.dg/other/friend12.C deleted file mode 100644 index b78ce4b078c..00000000000 --- a/gcc/testsuite/g++.dg/other/friend12.C +++ /dev/null @@ -1,11 +0,0 @@ -// PR c++/59480 - -template -class test { - friend int foo(bool = true) { return 1; } // { dg-message "14:previous" } - friend int foo(bool); // { dg-error "14:friend declaration" } - template friend int bar(bool = true) { return 1; } // { dg-message "33:previous" } - template friend int bar(bool); // { dg-error "33:friend declaration" } -}; - -template class test; diff --git a/gcc/testsuite/g++.dg/other/friend8.C b/gcc/testsuite/g++.dg/other/friend8.C deleted file mode 100644 index 6b5df88d6a4..00000000000 --- a/gcc/testsuite/g++.dg/other/friend8.C +++ /dev/null @@ -1,6 +0,0 @@ -// PR c++/59480 - -class test { - friend int foo(bool = true); // { dg-error "14:friend declaration" } - template friend int bar(bool = true); // { dg-error "33:friend declaration" } -}; diff --git a/gcc/testsuite/g++.dg/other/friend9.C b/gcc/testsuite/g++.dg/other/friend9.C deleted file mode 100644 index 16b4f57335d..00000000000 --- a/gcc/testsuite/g++.dg/other/friend9.C +++ /dev/null @@ -1,9 +0,0 @@ -// PR c++/59480 - -template -class test { - friend int foo(bool = true); // { dg-error "14:friend declaration" } - template friend int bar(bool = true); // { dg-error "33:friend declaration" } -}; - -template class test; diff --git a/gcc/testsuite/g++.dg/parse/defarg4.C b/gcc/testsuite/g++.dg/parse/defarg4.C index ad8a1ed6c65..151f6c5f668 100644 --- a/gcc/testsuite/g++.dg/parse/defarg4.C +++ b/gcc/testsuite/g++.dg/parse/defarg4.C @@ -1,4 +1,4 @@ -// { dg-options "-fpermissive -w" } +// { dg-do compile } // Copyright (C) 2003 Free Software Foundation, Inc. // Contributed by Nathan Sidwell 3 Jul 2003 diff --git a/gcc/testsuite/g++.dg/parse/defarg8.C b/gcc/testsuite/g++.dg/parse/defarg8.C index 33100069ead..1f1f078aa16 100644 --- a/gcc/testsuite/g++.dg/parse/defarg8.C +++ b/gcc/testsuite/g++.dg/parse/defarg8.C @@ -1,5 +1,3 @@ -// { dg-options "-fpermissive -w" } - struct A { static void g(int); }; diff --git a/gcc/testsuite/g++.old-deja/g++.mike/p784.C b/gcc/testsuite/g++.old-deja/g++.mike/p784.C index 44d03f109ab..04a70c2eee4 100644 --- a/gcc/testsuite/g++.old-deja/g++.mike/p784.C +++ b/gcc/testsuite/g++.old-deja/g++.mike/p784.C @@ -1,6 +1,6 @@ // { dg-do assemble } // { dg-require-effective-target ilp32 } */ -// { dg-options "-w -fpermissive" } +// { dg-options "-w" } // prms-id: 784 //# 1 "GctSymbol.GctSymbol.CHMap.cc" -- 2.30.2