[PATCH] D55246: AST: Relax an assertion in constexpr constructor evaluation.

Peter Collingbourne via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Dec 3 19:53:48 PST 2018


pcc created this revision.
pcc added a reviewer: rsmith.
Herald added a subscriber: llvm-commits.

It's possible for the base type specified in a constructor to be
qualified via sugar, so the existing assertion was too strict. Relax
it so that we only check that the unqualified types are the same.


Repository:
  rL LLVM

https://reviews.llvm.org/D55246

Files:
  clang/lib/AST/ExprConstant.cpp
  clang/test/SemaCXX/constant-expression-cxx11.cpp


Index: clang/test/SemaCXX/constant-expression-cxx11.cpp
===================================================================
--- clang/test/SemaCXX/constant-expression-cxx11.cpp
+++ clang/test/SemaCXX/constant-expression-cxx11.cpp
@@ -2220,3 +2220,15 @@
   constexpr int *q = (&n + 1) - (unsigned __int128)-1; // expected-error {{constant expression}} expected-note {{cannot refer to element -3402}}
   constexpr int *r = &(&n + 1)[(unsigned __int128)-1]; // expected-error {{constant expression}} expected-note {{cannot refer to element 3402}}
 }
+
+namespace QualifiedBaseType {
+  template <class T>
+  struct A : T {
+  public:
+    constexpr A() : T() {}
+  };
+
+  struct S {};
+
+  A<const S> a;
+}
Index: clang/lib/AST/ExprConstant.cpp
===================================================================
--- clang/lib/AST/ExprConstant.cpp
+++ clang/lib/AST/ExprConstant.cpp
@@ -4542,7 +4542,7 @@
       // Non-virtual base classes are initialized in the order in the class
       // definition. We have already checked for virtual base classes.
       assert(!BaseIt->isVirtual() && "virtual base for literal type");
-      assert(Info.Ctx.hasSameType(BaseIt->getType(), BaseType) &&
+      assert(Info.Ctx.hasSameUnqualifiedType(BaseIt->getType(), BaseType) &&
              "base class initializers not in expected order");
       ++BaseIt;
 #endif


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D55246.176538.patch
Type: text/x-patch
Size: 1358 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20181204/3a1e7631/attachment.bin>


More information about the cfe-commits mailing list