From: Richard Smith Date: Thu, 26 Apr 2012 01:51:03 +0000 (+0000) Subject: Two missing -Wc++98-compat warnings, for null pointers as non-type template X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=86e6fdcf1a04edc4c24f53f9dbacf7e1b52f306d;p=clang Two missing -Wc++98-compat warnings, for null pointers as non-type template arguments, and 'this' in exception-specifications. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@155606 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/Basic/DiagnosticSemaKinds.td b/include/clang/Basic/DiagnosticSemaKinds.td index 8826d0397b..f85a39ea5e 100644 --- a/include/clang/Basic/DiagnosticSemaKinds.td +++ b/include/clang/Basic/DiagnosticSemaKinds.td @@ -2365,6 +2365,9 @@ def err_template_arg_not_ice : Error< "expression">; def err_template_arg_not_address_constant : Error< "non-type template argument of type %0 is not a constant expression">; +def warn_cxx98_compat_template_arg_null : Warning< + "use of null pointer as non-type template argument is incompatible with " + "C++98">, InGroup, DefaultIgnore; def err_template_arg_untyped_null_constant : Error< "null non-type template argument must be cast to template parameter type %0">; def err_template_arg_wrongtype_null_constant : Error< @@ -3834,6 +3837,9 @@ def err_this_static_member_func : Error< "declaration">; def err_invalid_member_use_in_static_method : Error< "invalid use of member %0 in static member function">; +def warn_cxx98_compat_this_outside_method : Warning< + "use of 'this' outside a non-static member function is incompatible " + "with C++98">, InGroup, DefaultIgnore; def err_invalid_qualified_function_type : Error< "%select{static |non-}0member function %select{of type %2 |}1" "cannot have '%3' qualifier">; diff --git a/lib/Sema/SemaExprCXX.cpp b/lib/Sema/SemaExprCXX.cpp index af0f971c1c..7d345073d7 100644 --- a/lib/Sema/SemaExprCXX.cpp +++ b/lib/Sema/SemaExprCXX.cpp @@ -693,6 +693,10 @@ Sema::CXXThisScopeRAII::~CXXThisScopeRAII() { } void Sema::CheckCXXThisCapture(SourceLocation Loc, bool Explicit) { + if (getLangOpts().CPlusPlus0x && + !dyn_cast_or_null(getFunctionLevelDeclContext())) + Diag(Loc, diag::warn_cxx98_compat_this_outside_method); + // We don't need to capture this in an unevaluated context. if (ExprEvalContexts.back().Context == Unevaluated && !Explicit) return; diff --git a/lib/Sema/SemaTemplate.cpp b/lib/Sema/SemaTemplate.cpp index b9ea055a4c..be59068649 100644 --- a/lib/Sema/SemaTemplate.cpp +++ b/lib/Sema/SemaTemplate.cpp @@ -3589,6 +3589,7 @@ CheckTemplateArgumentAddressOfObjectOrFunction(Sema &S, if (ParamType->isPointerType() || ParamType->isNullPtrType()) { switch (isNullPointerValueTemplateArgument(S, Param, ParamType, Arg)) { case NPV_NullPointer: + S.Diag(Arg->getExprLoc(), diag::warn_cxx98_compat_template_arg_null); Converted = TemplateArgument((Decl *)0); return false; @@ -3885,6 +3886,7 @@ static bool CheckTemplateArgumentPointerToMember(Sema &S, case NPV_Error: return true; case NPV_NullPointer: + S.Diag(Arg->getExprLoc(), diag::warn_cxx98_compat_template_arg_null); Converted = TemplateArgument((Decl *)0); return false; case NPV_NotNullPointer: @@ -4320,6 +4322,7 @@ ExprResult Sema::CheckTemplateArgument(NonTypeTemplateParmDecl *Param, return ExprError(); case NPV_NullPointer: + Diag(Arg->getExprLoc(), diag::warn_cxx98_compat_template_arg_null); Converted = TemplateArgument((Decl *)0); return Owned(Arg);; } diff --git a/test/SemaCXX/cxx98-compat.cpp b/test/SemaCXX/cxx98-compat.cpp index 2688232122..8ac3234411 100644 --- a/test/SemaCXX/cxx98-compat.cpp +++ b/test/SemaCXX/cxx98-compat.cpp @@ -323,3 +323,21 @@ namespace NonTypeTemplateArgs { S s1; // expected-warning {{non-type template argument referring to object 'k' with internal linkage is incompatible with C++98}} S s2; // expected-warning {{non-type template argument referring to function 'f' with internal linkage is incompatible with C++98}} } + +namespace ThisInExceptionSpec { + template struct T {}; + struct S { + int n; + void f() throw (T); // expected-warning {{use of 'this' outside a non-static member function is incompatible with C++98}} + void g() throw (T); // expected-warning {{use of 'this' outside a non-static member function is incompatible with C++98}} + void h() throw (T); // expected-warning {{use of 'this' outside a non-static member function is incompatible with C++98}} + }; +} + +namespace NullPointerTemplateArg { + struct A {}; + template struct X {}; + template struct Y {}; + X<(int*)0> x; // expected-warning {{use of null pointer as non-type template argument is incompatible with C++98}} + Y<(int A::*)0> y; // expected-warning {{use of null pointer as non-type template argument is incompatible with C++98}} +}