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 ->.
llvm-svn: 143155
diff --git a/clang/lib/Sema/SemaExprMember.cpp b/clang/lib/Sema/SemaExprMember.cpp
index 5696e23..da09968 100644
--- a/clang/lib/Sema/SemaExprMember.cpp
+++ b/clang/lib/Sema/SemaExprMember.cpp
@@ -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);
diff --git a/clang/lib/Sema/SemaStmt.cpp b/clang/lib/Sema/SemaStmt.cpp
index f35b359..6dcfbba 100644
--- a/clang/lib/Sema/SemaStmt.cpp
+++ b/clang/lib/Sema/SemaStmt.cpp
@@ -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);
diff --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp
index d264188..de0193c 100644
--- a/clang/lib/Sema/SemaTemplate.cpp
+++ b/clang/lib/Sema/SemaTemplate.cpp
@@ -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