r210696 - Add missing "non-constant" diagnostic for a member call on a temporary of

Richard Smith richard-llvm at metafoo.co.uk
Wed Jun 11 12:53:12 PDT 2014


Author: rsmith
Date: Wed Jun 11 14:53:12 2014
New Revision: 210696

URL: http://llvm.org/viewvc/llvm-project?rev=210696&view=rev
Log:
Add missing "non-constant" diagnostic for a member call on a temporary of
non-literal class type.

Modified:
    cfe/trunk/lib/AST/ExprConstant.cpp
    cfe/trunk/test/CXX/dcl.dcl/dcl.spec/dcl.constexpr/p6.cpp
    cfe/trunk/test/SemaCXX/constant-expression-cxx11.cpp

Modified: cfe/trunk/lib/AST/ExprConstant.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ExprConstant.cpp?rev=210696&r1=210695&r2=210696&view=diff
==============================================================================
--- cfe/trunk/lib/AST/ExprConstant.cpp (original)
+++ cfe/trunk/lib/AST/ExprConstant.cpp Wed Jun 11 14:53:12 2014
@@ -2938,6 +2938,7 @@ static bool EvaluateObjectArgument(EvalI
   if (Object->getType()->isLiteralType(Info.Ctx))
     return EvaluateTemporary(Object, This, Info);
 
+  Info.Diag(Object, diag::note_constexpr_nonliteral) << Object->getType();
   return false;
 }
 

Modified: cfe/trunk/test/CXX/dcl.dcl/dcl.spec/dcl.constexpr/p6.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/dcl.dcl/dcl.spec/dcl.constexpr/p6.cpp?rev=210696&r1=210695&r2=210696&view=diff
==============================================================================
--- cfe/trunk/test/CXX/dcl.dcl/dcl.spec/dcl.constexpr/p6.cpp (original)
+++ cfe/trunk/test/CXX/dcl.dcl/dcl.spec/dcl.constexpr/p6.cpp Wed Jun 11 14:53:12 2014
@@ -35,7 +35,7 @@ template<typename R> struct ConstexprMem
   constexpr R F() const { return 0; }
 };
 constexpr int d = ConstexprMember<int>().F(); // ok
-constexpr int e = ConstexprMember<NonLiteral>().F(); // expected-error {{constant expression}}
+constexpr int e = ConstexprMember<NonLiteral>().F(); // expected-error {{constant expression}} expected-note {{non-literal type 'const NonLiteral' cannot be used in a constant expression}}
 
 template<typename ...P> struct ConstexprCtor {
   constexpr ConstexprCtor(P...) {}

Modified: cfe/trunk/test/SemaCXX/constant-expression-cxx11.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/constant-expression-cxx11.cpp?rev=210696&r1=210695&r2=210696&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/constant-expression-cxx11.cpp (original)
+++ cfe/trunk/test/SemaCXX/constant-expression-cxx11.cpp Wed Jun 11 14:53:12 2014
@@ -860,6 +860,12 @@ static_assert(f(T(5)) == 5, "");
 constexpr bool b(int n) { return &n; }
 static_assert(b(0), "");
 
+struct NonLiteral {
+  NonLiteral();
+  int f();
+};
+constexpr int k = NonLiteral().f(); // expected-error {{constant expression}} expected-note {{non-literal type 'Temporaries::NonLiteral'}}
+
 }
 
 namespace Union {





More information about the cfe-commits mailing list