[cfe-commits] r155606 - in /cfe/trunk: include/clang/Basic/DiagnosticSemaKinds.td lib/Sema/SemaExprCXX.cpp lib/Sema/SemaTemplate.cpp test/SemaCXX/cxx98-compat.cpp

Richard Smith richard-llvm at metafoo.co.uk
Wed Apr 25 18:51:04 PDT 2012


Author: rsmith
Date: Wed Apr 25 20:51:03 2012
New Revision: 155606

URL: http://llvm.org/viewvc/llvm-project?rev=155606&view=rev
Log:
Two missing -Wc++98-compat warnings, for null pointers as non-type template
arguments, and 'this' in exception-specifications.

Modified:
    cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
    cfe/trunk/lib/Sema/SemaExprCXX.cpp
    cfe/trunk/lib/Sema/SemaTemplate.cpp
    cfe/trunk/test/SemaCXX/cxx98-compat.cpp

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=155606&r1=155605&r2=155606&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Wed Apr 25 20:51:03 2012
@@ -2365,6 +2365,9 @@
   "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<CXX98Compat>, 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 @@
   "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<CXX98Compat>, DefaultIgnore;
 def err_invalid_qualified_function_type : Error<
   "%select{static |non-}0member function %select{of type %2 |}1"
   "cannot have '%3' qualifier">;

Modified: cfe/trunk/lib/Sema/SemaExprCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExprCXX.cpp?rev=155606&r1=155605&r2=155606&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExprCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExprCXX.cpp Wed Apr 25 20:51:03 2012
@@ -693,6 +693,10 @@
 }
 
 void Sema::CheckCXXThisCapture(SourceLocation Loc, bool Explicit) {
+  if (getLangOpts().CPlusPlus0x &&
+      !dyn_cast_or_null<CXXMethodDecl>(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;

Modified: cfe/trunk/lib/Sema/SemaTemplate.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplate.cpp?rev=155606&r1=155605&r2=155606&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaTemplate.cpp (original)
+++ cfe/trunk/lib/Sema/SemaTemplate.cpp Wed Apr 25 20:51:03 2012
@@ -3589,6 +3589,7 @@
   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 @@
   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 @@
       return ExprError();
       
     case NPV_NullPointer:
+      Diag(Arg->getExprLoc(), diag::warn_cxx98_compat_template_arg_null);
       Converted = TemplateArgument((Decl *)0);
       return Owned(Arg);;
     }

Modified: cfe/trunk/test/SemaCXX/cxx98-compat.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/cxx98-compat.cpp?rev=155606&r1=155605&r2=155606&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/cxx98-compat.cpp (original)
+++ cfe/trunk/test/SemaCXX/cxx98-compat.cpp Wed Apr 25 20:51:03 2012
@@ -323,3 +323,21 @@
   S<const int&, k> s1; // expected-warning {{non-type template argument referring to object 'k' with internal linkage is incompatible with C++98}}
   S<void(&)(), f> s2; // expected-warning {{non-type template argument referring to function 'f' with internal linkage is incompatible with C++98}}
 }
+
+namespace ThisInExceptionSpec {
+  template<int> struct T {};
+  struct S {
+    int n;
+    void f() throw (T<sizeof(n)>); // expected-warning {{use of 'this' outside a non-static member function is incompatible with C++98}}
+    void g() throw (T<sizeof(S::n)>); // expected-warning {{use of 'this' outside a non-static member function is incompatible with C++98}}
+    void h() throw (T<sizeof(this)>); // expected-warning {{use of 'this' outside a non-static member function is incompatible with C++98}}
+  };
+}
+
+namespace NullPointerTemplateArg {
+  struct A {};
+  template<int*> struct X {};
+  template<int A::*> 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}}
+}





More information about the cfe-commits mailing list