[cfe-commits] r143155 - in /cfe/trunk: lib/Sema/SemaExprMember.cpp lib/Sema/SemaStmt.cpp lib/Sema/SemaTemplate.cpp test/SemaCXX/constant-expression-cxx11.cpp

Richard Smith richard-llvm at metafoo.co.uk
Thu Oct 27 15:11:44 PDT 2011


Author: rsmith
Date: Thu Oct 27 17:11:44 2011
New Revision: 143155

URL: http://llvm.org/viewvc/llvm-project?rev=143155&view=rev
Log:
Fix some cases where a CK_IntegralCast was being used to convert an lvalue to an
rvalue. An assertion to catch this is in ImpCastExprToType will follow, but
vector operations currently trip over this (due to omitting the usual arithmetic
conversions). Also add an assert to catch missing lvalue-to-rvalue conversions
on the LHS of ->.

Added:
    cfe/trunk/test/SemaCXX/constant-expression-cxx11.cpp
Modified:
    cfe/trunk/lib/Sema/SemaExprMember.cpp
    cfe/trunk/lib/Sema/SemaStmt.cpp
    cfe/trunk/lib/Sema/SemaTemplate.cpp

Modified: cfe/trunk/lib/Sema/SemaExprMember.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExprMember.cpp?rev=143155&r1=143154&r2=143155&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExprMember.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExprMember.cpp Thu Oct 27 17:11:44 2011
@@ -761,6 +761,7 @@
                                    QualType Ty,
                                    ExprValueKind VK, ExprObjectKind OK,
                                    const TemplateArgumentListInfo *TemplateArgs = 0) {
+  assert((!isArrow || Base->isRValue()) && "-> base must be a pointer rvalue");
   return MemberExpr::Create(C, Base, isArrow, SS.getWithLocInContext(C),
                             Member, FoundDecl, MemberNameInfo,
                             TemplateArgs, Ty, VK, OK);

Modified: cfe/trunk/lib/Sema/SemaStmt.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaStmt.cpp?rev=143155&r1=143154&r2=143155&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaStmt.cpp (original)
+++ cfe/trunk/lib/Sema/SemaStmt.cpp Thu Oct 27 17:11:44 2011
@@ -639,6 +639,9 @@
 
       // If the LHS is not the same type as the condition, insert an implicit
       // cast.
+      // FIXME: In C++11, the value is a converted constant expression of the
+      // promoted type of the switch condition.
+      Lo = DefaultLvalueConversion(Lo).take();
       Lo = ImpCastExprToType(Lo, CondType, CK_IntegralCast).take();
       CS->setLHS(Lo);
 
@@ -716,8 +719,11 @@
                                            Hi->getLocStart(),
                                            diag::warn_case_value_overflow);
 
-        // If the LHS is not the same type as the condition, insert an implicit
+        // If the RHS is not the same type as the condition, insert an implicit
         // cast.
+        // FIXME: In C++11, the value is a converted constant expression of the
+        // promoted type of the switch condition.
+        Hi = DefaultLvalueConversion(Hi).take();
         Hi = ImpCastExprToType(Hi, CondType, CK_IntegralCast).take();
         CR->setRHS(Hi);
 

Modified: cfe/trunk/lib/Sema/SemaTemplate.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplate.cpp?rev=143155&r1=143154&r2=143155&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaTemplate.cpp (original)
+++ cfe/trunk/lib/Sema/SemaTemplate.cpp Thu Oct 27 17:11:44 2011
@@ -3743,8 +3743,16 @@
   //        enumeration type, integral promotions (4.5) and integral
   //        conversions (4.7) are applied.
   QualType ParamType = InstantiatedParamType;
-  QualType ArgType = Arg->getType();
   if (ParamType->isIntegralOrEnumerationType()) {
+    // FIXME: In C++11, the argument is a converted constant expression of the
+    // type of the template parameter.
+    ExprResult ArgResult = DefaultLvalueConversion(Arg);
+    if (ArgResult.isInvalid())
+      return ExprError();
+    Arg = ArgResult.take();
+
+    QualType ArgType = Arg->getType();
+
     // C++ [temp.arg.nontype]p1:
     //   A template-argument for a non-type, non-template
     //   template-parameter shall be one of:
@@ -3868,6 +3876,7 @@
     return Owned(Arg);
   }
 
+  QualType ArgType = Arg->getType();
   DeclAccessPair FoundResult; // temporary for ResolveOverloadedFunction
 
   // C++0x [temp.arg.nontype]p5 bullets 2, 4 and 6 permit conversion

Added: cfe/trunk/test/SemaCXX/constant-expression-cxx11.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/constant-expression-cxx11.cpp?rev=143155&view=auto
==============================================================================
--- cfe/trunk/test/SemaCXX/constant-expression-cxx11.cpp (added)
+++ cfe/trunk/test/SemaCXX/constant-expression-cxx11.cpp Thu Oct 27 17:11:44 2011
@@ -0,0 +1,28 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s
+
+template<typename T> constexpr T id(const T &t) { return t; }
+
+struct MemberZero {
+  constexpr int zero() { return 0; }
+};
+
+namespace TemplateArgumentConversion {
+  template<int n> struct IntParam {};
+
+  using IntParam0 = IntParam<0>;
+  // FIXME: This should be accepted once we do constexpr function invocation.
+  using IntParam0 = IntParam<id(0)>; // expected-error {{not an integral constant expression}}
+  using IntParam0 = IntParam<MemberZero().zero>; // expected-error {{did you mean to call it with no arguments?}} expected-error {{not an integral constant expression}}
+}
+
+namespace CaseStatements {
+  void f(int n) {
+    switch (n) {
+    // FIXME: Produce the 'add ()' fixit for this.
+    case MemberZero().zero: // desired-error {{did you mean to call it with no arguments?}} expected-error {{not an integer constant expression}}
+    // FIXME: This should be accepted once we do constexpr function invocation.
+    case id(1): // expected-error {{not an integer constant expression}}
+      return;
+    }
+  }
+}





More information about the cfe-commits mailing list