r182433 - PR16090: C++1y: treat undeduced 'auto' as a literal type, so that constexpr

Richard Smith richard-llvm at metafoo.co.uk
Tue May 21 15:29:20 PDT 2013


Author: rsmith
Date: Tue May 21 17:29:20 2013
New Revision: 182433

URL: http://llvm.org/viewvc/llvm-project?rev=182433&view=rev
Log:
PR16090: C++1y: treat undeduced 'auto' as a literal type, so that constexpr
function templates can use it as a return type.

Modified:
    cfe/trunk/lib/AST/Type.cpp
    cfe/trunk/test/SemaCXX/constant-expression-cxx1y.cpp

Modified: cfe/trunk/lib/AST/Type.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Type.cpp?rev=182433&r1=182432&r2=182433&view=diff
==============================================================================
--- cfe/trunk/lib/AST/Type.cpp (original)
+++ cfe/trunk/lib/AST/Type.cpp Tue May 21 17:29:20 2013
@@ -1196,6 +1196,11 @@ bool Type::isLiteralType(ASTContext &Ctx
     return true;
   }
 
+  // If this type hasn't been deduced yet, then conservatively assume that
+  // it'll work out to be a literal type.
+  if (isa<AutoType>(BaseTy->getCanonicalTypeInternal()))
+    return true;
+
   return false;
 }
 

Modified: cfe/trunk/test/SemaCXX/constant-expression-cxx1y.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/constant-expression-cxx1y.cpp?rev=182433&r1=182432&r2=182433&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/constant-expression-cxx1y.cpp (original)
+++ cfe/trunk/test/SemaCXX/constant-expression-cxx1y.cpp Tue May 21 17:29:20 2013
@@ -708,3 +708,10 @@ namespace switch_stmt {
   static_assert(test_copy("hello world", 10), "");
   static_assert(test_copy("hello world", 10), "");
 }
+
+namespace deduced_return_type {
+  constexpr auto f() { return 0; }
+  template<typename T> constexpr auto g(T t) { return t; }
+  static_assert(f() == 0, "");
+  static_assert(g(true), "");
+}





More information about the cfe-commits mailing list