From 3bdb38bfc3244d28b03035034b78afcb7187b87c Mon Sep 17 00:00:00 2001 From: Nico Weber Date: Thu, 18 Sep 2014 02:09:53 +0000 Subject: [PATCH] Change -Wbind-to-temporary-copy from an ExtWarn to an Extension. The reasoning is that this construct is accepted by all compilers and valid in C++11, so it doesn't seem like a useful warning to have enabled by default. Building with -pedantic, -Wbind-to-temporary-copy, or -Wc++98-compat still shows the warning. The motivation is that I built re2, and this was the only warning that was emitted during the build. Both changing re2 to fix the warning and detecting clang and suppressing the warning in re2's build seem inferior than just giving the compiler a good default for this warning. Also move the cxx98compat version of this warning to CXX98CompatPedantic, and update tests accordingly. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@218008 91177308-0d34-0410-b5e6-96231b3b80d8 --- docs/UsersManual.rst | 2 +- include/clang/Basic/DiagnosticGroups.td | 4 +-- include/clang/Basic/DiagnosticSemaKinds.td | 4 +-- .../dcl.init.ref/p5-cxx03-extra-copy.cpp | 2 +- test/SemaCXX/conversion-function.cpp | 2 +- test/SemaCXX/cxx98-compat-flags.cpp | 4 +-- test/SemaCXX/cxx98-compat-pedantic.cpp | 29 ++++++++++++++++++- test/SemaCXX/cxx98-compat.cpp | 27 +---------------- test/SemaCXX/undefined-internal.cpp | 2 +- 9 files changed, 39 insertions(+), 37 deletions(-) diff --git a/docs/UsersManual.rst b/docs/UsersManual.rst index 90d2365ea7..a5d8148810 100644 --- a/docs/UsersManual.rst +++ b/docs/UsersManual.rst @@ -481,7 +481,7 @@ TODO: Generate this from tblgen. Define one anchor per warning group. Warn about an unusable copy constructor when binding a reference to a temporary. - This option, which defaults to on, enables warnings about binding a + This option enables warnings about binding a reference to a temporary when the temporary doesn't have a usable copy constructor. For example: diff --git a/include/clang/Basic/DiagnosticGroups.td b/include/clang/Basic/DiagnosticGroups.td index 1ebe037ca3..ea733876e8 100644 --- a/include/clang/Basic/DiagnosticGroups.td +++ b/include/clang/Basic/DiagnosticGroups.td @@ -133,14 +133,14 @@ def CXX98CompatUnnamedTypeTemplateArgs : DiagGroup<"c++98-compat-unnamed-type-template-args">; def CXX98Compat : DiagGroup<"c++98-compat", - [CXX98CompatBindToTemporaryCopy, - CXX98CompatLocalTypeTemplateArgs, + [CXX98CompatLocalTypeTemplateArgs, CXX98CompatUnnamedTypeTemplateArgs, CXXPre14Compat, CXXPre1zCompat]>; // Warnings for C++11 features which are Extensions in C++98 mode. def CXX98CompatPedantic : DiagGroup<"c++98-compat-pedantic", [CXX98Compat, + CXX98CompatBindToTemporaryCopy, CXXPre14CompatPedantic, CXXPre1zCompatPedantic]>; diff --git a/include/clang/Basic/DiagnosticSemaKinds.td b/include/clang/Basic/DiagnosticSemaKinds.td index 7852dc78bd..d955e4eaff 100644 --- a/include/clang/Basic/DiagnosticSemaKinds.td +++ b/include/clang/Basic/DiagnosticSemaKinds.td @@ -1118,7 +1118,7 @@ def ext_ms_using_declaration_inaccessible : ExtWarn< def err_access_ctor : Error< "calling a %select{private|protected}0 constructor of class %2">, AccessControl; -def ext_rvalue_to_reference_access_ctor : ExtWarn< +def ext_rvalue_to_reference_access_ctor : Extension< "C++98 requires an accessible copy constructor for class %2 when binding " "a reference to a temporary; was %select{private|protected}0">, AccessControl, InGroup; @@ -1545,7 +1545,7 @@ def err_temp_copy_no_viable : Error< "returning object|throwing object|copying member subobject|copying array " "element|allocating object|copying temporary|initializing base subobject|" "initializing vector element|capturing value}0 of type %1">; -def ext_rvalue_to_reference_temp_copy_no_viable : ExtWarn< +def ext_rvalue_to_reference_temp_copy_no_viable : Extension< "no viable constructor %select{copying variable|copying parameter|" "returning object|throwing object|copying member subobject|copying array " "element|allocating object|copying temporary|initializing base subobject|" diff --git a/test/CXX/dcl.decl/dcl.init/dcl.init.ref/p5-cxx03-extra-copy.cpp b/test/CXX/dcl.decl/dcl.init/dcl.init.ref/p5-cxx03-extra-copy.cpp index 4ba75efebb..f86b24e992 100644 --- a/test/CXX/dcl.decl/dcl.init/dcl.init.ref/p5-cxx03-extra-copy.cpp +++ b/test/CXX/dcl.decl/dcl.init/dcl.init.ref/p5-cxx03-extra-copy.cpp @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -fsyntax-only -fdiagnostics-show-option -verify %s +// RUN: %clang_cc1 -fsyntax-only -fdiagnostics-show-option -Wbind-to-temporary-copy -verify %s // C++03 requires that we check for a copy constructor when binding a // reference to a temporary, since we are allowed to make a copy, Even diff --git a/test/SemaCXX/conversion-function.cpp b/test/SemaCXX/conversion-function.cpp index 40ac33b8eb..ede23a2767 100644 --- a/test/SemaCXX/conversion-function.cpp +++ b/test/SemaCXX/conversion-function.cpp @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -fsyntax-only -verify %s +// RUN: %clang_cc1 -fsyntax-only -Wbind-to-temporary-copy -verify %s class X { public: operator bool(); diff --git a/test/SemaCXX/cxx98-compat-flags.cpp b/test/SemaCXX/cxx98-compat-flags.cpp index 6dc24be6bb..f90ad345e9 100644 --- a/test/SemaCXX/cxx98-compat-flags.cpp +++ b/test/SemaCXX/cxx98-compat-flags.cpp @@ -1,5 +1,5 @@ -// RUN: %clang_cc1 -fsyntax-only -std=c++11 -Wc++98-compat -verify %s -// RUN: %clang_cc1 -fsyntax-only -std=c++11 -Wc++98-compat -Wno-bind-to-temporary-copy -Wno-unnamed-type-template-args -Wno-local-type-template-args -Werror %s +// RUN: %clang_cc1 -fsyntax-only -std=c++11 -Wc++98-compat-pedantic -verify %s +// RUN: %clang_cc1 -fsyntax-only -std=c++11 -Wc++98-compat-pedantic -Wno-bind-to-temporary-copy -Wno-unnamed-type-template-args -Wno-local-type-template-args -Werror %s template int TemplateFn(T) { return 0; } void LocalTemplateArg() { diff --git a/test/SemaCXX/cxx98-compat-pedantic.cpp b/test/SemaCXX/cxx98-compat-pedantic.cpp index 9eb0da33f3..38bc341e83 100644 --- a/test/SemaCXX/cxx98-compat-pedantic.cpp +++ b/test/SemaCXX/cxx98-compat-pedantic.cpp @@ -2,7 +2,7 @@ // RUN: %clang_cc1 -fsyntax-only -std=c++1y -DCXX1Y -Wc++98-compat -Werror %s -DCXX1Y2 // RUN: %clang_cc1 -fsyntax-only -std=c++11 -Wc++98-compat-pedantic -verify %s // RUN: %clang_cc1 -fsyntax-only -std=c++11 -Wc++98-compat -Werror %s -// RUN: %clang_cc1 -fsyntax-only -std=c++98 -Werror %s +// RUN: %clang_cc1 -fsyntax-only -std=c++98 -Werror %s -DCXX98 // RUN: %clang_cc1 -fsyntax-only -std=c++1y -Wc++98-compat-pedantic -verify %s -Wno-c++98-c++11-compat-pedantic -DCXX1Y2 @@ -51,3 +51,30 @@ int k = 0b1001; #ifdef CXX1Y // expected-warning@-2 {{binary integer literals are incompatible with C++ standards before C++14}} #endif + +namespace CopyCtorIssues { + struct Private { + Private(); + private: + Private(const Private&); // expected-note {{declared private here}} + }; + struct NoViable { + NoViable(); + NoViable(NoViable&); // expected-note {{not viable}} + }; + struct Ambiguous { + Ambiguous(); + Ambiguous(const Ambiguous &, int = 0); // expected-note {{candidate}} + Ambiguous(const Ambiguous &, double = 0); // expected-note {{candidate}} + }; + struct Deleted { + Private p; // expected-note {{implicitly deleted}} + }; + + const Private &a = Private(); // expected-warning {{copying variable of type 'CopyCtorIssues::Private' when binding a reference to a temporary would invoke an inaccessible constructor in C++98}} + const NoViable &b = NoViable(); // expected-warning {{copying variable of type 'CopyCtorIssues::NoViable' when binding a reference to a temporary would find no viable constructor in C++98}} +#if !CXX98 + const Ambiguous &c = Ambiguous(); // expected-warning {{copying variable of type 'CopyCtorIssues::Ambiguous' when binding a reference to a temporary would find ambiguous constructors in C++98}} +#endif + const Deleted &d = Deleted(); // expected-warning {{copying variable of type 'CopyCtorIssues::Deleted' when binding a reference to a temporary would invoke a deleted constructor in C++98}} +} diff --git a/test/SemaCXX/cxx98-compat.cpp b/test/SemaCXX/cxx98-compat.cpp index f4c15c4f74..029e909896 100644 --- a/test/SemaCXX/cxx98-compat.cpp +++ b/test/SemaCXX/cxx98-compat.cpp @@ -1,5 +1,5 @@ // RUN: %clang_cc1 -fsyntax-only -std=c++11 -Wc++98-compat -verify %s -// RUN: %clang_cc1 -fsyntax-only -std=c++1y -Wc++98-compat -verify %s -DCXX14COMPAT +// RUN: %clang_cc1 -fsyntax-only -std=c++14 -Wc++98-compat -verify %s -DCXX14COMPAT namespace std { struct type_info; @@ -225,31 +225,6 @@ template typename T::ImPrivate SFINAEAccessControl(T t) { // expecte int SFINAEAccessControl(...) { return 0; } int CheckSFINAEAccessControl = SFINAEAccessControl(PrivateMember()); // expected-note {{while substituting deduced template arguments into function template 'SFINAEAccessControl' [with T = PrivateMember]}} -namespace CopyCtorIssues { - struct Private { - Private(); - private: - Private(const Private&); // expected-note {{declared private here}} - }; - struct NoViable { - NoViable(); - NoViable(NoViable&); // expected-note {{not viable}} - }; - struct Ambiguous { - Ambiguous(); - Ambiguous(const Ambiguous &, int = 0); // expected-note {{candidate}} - Ambiguous(const Ambiguous &, double = 0); // expected-note {{candidate}} - }; - struct Deleted { - Private p; // expected-note {{implicitly deleted}} - }; - - const Private &a = Private(); // expected-warning {{copying variable of type 'CopyCtorIssues::Private' when binding a reference to a temporary would invoke an inaccessible constructor in C++98}} - const NoViable &b = NoViable(); // expected-warning {{copying variable of type 'CopyCtorIssues::NoViable' when binding a reference to a temporary would find no viable constructor in C++98}} - const Ambiguous &c = Ambiguous(); // expected-warning {{copying variable of type 'CopyCtorIssues::Ambiguous' when binding a reference to a temporary would find ambiguous constructors in C++98}} - const Deleted &d = Deleted(); // expected-warning {{copying variable of type 'CopyCtorIssues::Deleted' when binding a reference to a temporary would invoke a deleted constructor in C++98}} -} - namespace UnionOrAnonStructMembers { struct NonTrivCtor { NonTrivCtor(); // expected-note 2{{user-provided default constructor}} diff --git a/test/SemaCXX/undefined-internal.cpp b/test/SemaCXX/undefined-internal.cpp index f32036a025..d829380a7d 100644 --- a/test/SemaCXX/undefined-internal.cpp +++ b/test/SemaCXX/undefined-internal.cpp @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -fsyntax-only -verify %s +// RUN: %clang_cc1 -fsyntax-only -verify -Wbind-to-temporary-copy %s // Make sure we don't produce invalid IR. // RUN: %clang_cc1 -emit-llvm-only %s -- 2.50.1