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.

llvm-svn: 218008
This commit is contained in:
Nico Weber 2014-09-18 02:09:53 +00:00
parent 9f1215b2d8
commit acb35c0272
9 changed files with 39 additions and 37 deletions

View File

@ -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:

View File

@ -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]>;

View File

@ -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<BindToTemporaryCopy>;
@ -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|"

View File

@ -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

View File

@ -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();

View File

@ -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<typename T> int TemplateFn(T) { return 0; }
void LocalTemplateArg() {

View File

@ -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}}
}

View File

@ -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> 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}}

View File

@ -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