aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnders Carlsson <andersca@mac.com>2009-06-26 03:02:18 +0000
committerAnders Carlsson <andersca@mac.com>2009-06-26 03:02:18 +0000
commit87471f5b64783c52e01e7accc1b123560b52bf35 (patch)
tree04f070d083a53eadced8eff9521f0bef75084e59
parent58d29a41271d96509f464716f79b0ab2e815b6b1 (diff)
Fix PR4448.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@74257 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/Parse/ParseDeclCXX.cpp2
-rw-r--r--lib/Sema/SemaTemplateInstantiate.cpp5
-rw-r--r--lib/Sema/SemaTemplateInstantiateExpr.cpp8
-rw-r--r--test/SemaCXX/decltype-pr4448.cpp8
4 files changed, 21 insertions, 2 deletions
diff --git a/lib/Parse/ParseDeclCXX.cpp b/lib/Parse/ParseDeclCXX.cpp
index 188580de20..fed03a8c34 100644
--- a/lib/Parse/ParseDeclCXX.cpp
+++ b/lib/Parse/ParseDeclCXX.cpp
@@ -365,14 +365,12 @@ void Parser::ParseDecltypeSpecifier(DeclSpec &DS) {
SourceLocation StartLoc = ConsumeToken();
SourceLocation LParenLoc = Tok.getLocation();
-
if (ExpectAndConsume(tok::l_paren, diag::err_expected_lparen_after,
"decltype")) {
SkipUntil(tok::r_paren);
return;
}
-
// Parse the expression
// C++0x [dcl.type.simple]p4:
diff --git a/lib/Sema/SemaTemplateInstantiate.cpp b/lib/Sema/SemaTemplateInstantiate.cpp
index 5e4fde7af9..0c78c71206 100644
--- a/lib/Sema/SemaTemplateInstantiate.cpp
+++ b/lib/Sema/SemaTemplateInstantiate.cpp
@@ -560,6 +560,11 @@ TemplateTypeInstantiator::InstantiateTypeOfType(const TypeOfType *T,
QualType
TemplateTypeInstantiator::InstantiateDecltypeType(const DecltypeType *T,
unsigned Quals) const {
+ // C++0x [dcl.type.simple]p4:
+ // The operand of the decltype specifier is an unevaluated operand.
+ EnterExpressionEvaluationContext Unevaluated(SemaRef,
+ Action::Unevaluated);
+
Sema::OwningExprResult E
= SemaRef.InstantiateExpr(T->getUnderlyingExpr(), TemplateArgs);
diff --git a/lib/Sema/SemaTemplateInstantiateExpr.cpp b/lib/Sema/SemaTemplateInstantiateExpr.cpp
index aba2c99ef8..65a35f92f7 100644
--- a/lib/Sema/SemaTemplateInstantiateExpr.cpp
+++ b/lib/Sema/SemaTemplateInstantiateExpr.cpp
@@ -119,6 +119,14 @@ TemplateExprInstantiator::VisitDeclRefExpr(DeclRefExpr *E) {
// FIXME: Clone the expression!
return SemaRef.Owned(Arg.getAsExpr());
+ if (Arg.getKind() == TemplateArgument::Declaration) {
+ ValueDecl *VD = cast<ValueDecl>(Arg.getAsDecl());
+
+ // FIXME: Can VD ever have a dependent type?
+ return SemaRef.BuildDeclRefExpr(VD, VD->getType(), E->getLocation(),
+ false, false);
+ }
+
assert(Arg.getKind() == TemplateArgument::Integral);
QualType T = Arg.getIntegralType();
if (T->isCharType() || T->isWideCharType())
diff --git a/test/SemaCXX/decltype-pr4448.cpp b/test/SemaCXX/decltype-pr4448.cpp
new file mode 100644
index 0000000000..fbf5da1d53
--- /dev/null
+++ b/test/SemaCXX/decltype-pr4448.cpp
@@ -0,0 +1,8 @@
+// RUN: clang-cc -fsyntax-only -verify %s -std=c++0x
+
+template< typename T, T t, decltype(t+2) v >
+struct Convoluted {};
+
+int test_array[5];
+
+Convoluted< int *, test_array, nullptr > tarray;