[cfe-commits] r148787 - in /cfe/trunk: lib/Parse/ParseExpr.cpp lib/Parse/ParseExprCXX.cpp lib/Parse/ParseTentative.cpp test/CXX/expr/expr.post/expr.type.conv/p1-0x.cpp test/CXX/stmt.stmt/stmt.ambig/p1-0x.cpp
David Blaikie
dblaikie at gmail.com
Mon Jan 23 21:47:35 PST 2012
Author: dblaikie
Date: Mon Jan 23 23:47:35 2012
New Revision: 148787
URL: http://llvm.org/viewvc/llvm-project?rev=148787&view=rev
Log:
Support decltype as a simple-type-specifier.
This makes all sorts of fun examples work with decltype.
Reviewed by Richard Smith.
Added:
cfe/trunk/test/CXX/expr/expr.post/expr.type.conv/p1-0x.cpp
cfe/trunk/test/CXX/stmt.stmt/stmt.ambig/p1-0x.cpp
Modified:
cfe/trunk/lib/Parse/ParseExpr.cpp
cfe/trunk/lib/Parse/ParseExprCXX.cpp
cfe/trunk/lib/Parse/ParseTentative.cpp
Modified: cfe/trunk/lib/Parse/ParseExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseExpr.cpp?rev=148787&r1=148786&r2=148787&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseExpr.cpp (original)
+++ cfe/trunk/lib/Parse/ParseExpr.cpp Mon Jan 23 23:47:35 2012
@@ -914,6 +914,7 @@
}
// Fall through
+ case tok::annot_decltype:
case tok::kw_char:
case tok::kw_wchar_t:
case tok::kw_char16_t:
Modified: cfe/trunk/lib/Parse/ParseExprCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseExprCXX.cpp?rev=148787&r1=148786&r2=148787&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseExprCXX.cpp (original)
+++ cfe/trunk/lib/Parse/ParseExprCXX.cpp Mon Jan 23 23:47:35 2012
@@ -1418,8 +1418,11 @@
case tok::kw_bool:
DS.SetTypeSpecType(DeclSpec::TST_bool, Loc, PrevSpec, DiagID);
break;
+ case tok::annot_decltype:
+ case tok::kw_decltype:
+ DS.SetRangeEnd(ParseDecltypeSpecifier(DS));
+ return DS.Finish(Diags, PP);
- // FIXME: C++0x decltype support.
// GNU typeof support.
case tok::kw_typeof:
ParseTypeofSpecifier(DS);
Modified: cfe/trunk/lib/Parse/ParseTentative.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseTentative.cpp?rev=148787&r1=148786&r2=148787&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseTentative.cpp (original)
+++ cfe/trunk/lib/Parse/ParseTentative.cpp Mon Jan 23 23:47:35 2012
@@ -1009,6 +1009,7 @@
case tok::kw_float:
case tok::kw_double:
case tok::kw_void:
+ case tok::annot_decltype:
if (NextToken().is(tok::l_paren))
return TPResult::Ambiguous();
@@ -1038,10 +1039,6 @@
return TPResult::True();
}
- // C++0x decltype support.
- case tok::annot_decltype:
- return TPResult::True();
-
// C++0x type traits support
case tok::kw___underlying_type:
return TPResult::True();
Added: cfe/trunk/test/CXX/expr/expr.post/expr.type.conv/p1-0x.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/expr/expr.post/expr.type.conv/p1-0x.cpp?rev=148787&view=auto
==============================================================================
--- cfe/trunk/test/CXX/expr/expr.post/expr.type.conv/p1-0x.cpp (added)
+++ cfe/trunk/test/CXX/expr/expr.post/expr.type.conv/p1-0x.cpp Mon Jan 23 23:47:35 2012
@@ -0,0 +1,12 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s
+
+struct foo {
+ foo();
+ foo(int);
+};
+
+int func(foo& f) {
+ decltype(foo())();
+ f = (decltype(foo()))5;
+ return decltype(3)(5);
+}
Added: cfe/trunk/test/CXX/stmt.stmt/stmt.ambig/p1-0x.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/stmt.stmt/stmt.ambig/p1-0x.cpp?rev=148787&view=auto
==============================================================================
--- cfe/trunk/test/CXX/stmt.stmt/stmt.ambig/p1-0x.cpp (added)
+++ cfe/trunk/test/CXX/stmt.stmt/stmt.ambig/p1-0x.cpp Mon Jan 23 23:47:35 2012
@@ -0,0 +1,40 @@
+// RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify %s
+
+struct T {
+ struct x {
+ int m;
+ };
+ x* operator->();
+ void operator++(int);
+ void operator<<(int);
+ T();
+ T(int);
+ T(int, int);
+};
+
+template<typename A, typename B, typename C, typename D, typename E>
+void func(A, B, C, D, E);
+
+void func(int a, int c) {
+ T(a)->m = 7;
+ T(a)++;
+ T(a,5)<<c;
+
+ T(*d)(int);
+ T(e)[5];
+ T(f) = {1, 2};
+ T(*g)(double(3)); // expected-error{{cannot initialize a variable of type 'T (*)' with an rvalue of type 'double'}}
+ func(a, d, e, f, g);
+}
+
+void func2(int a, int c) {
+ decltype(T())(a)->m = 7;
+ decltype(T())(a)++;
+ decltype(T())(a,5)<<c;
+
+ decltype(T())(*d)(int);
+ decltype(T())(e)[5];
+ decltype(T())(f) = {1, 2};
+ decltype(T())(*g)(double(3)); // expected-error{{cannot initialize a variable of type 'decltype(T()) (*)' (aka 'T *') with an rvalue of type 'double'}}
+ func(a, d, e, f, g);
+}
More information about the cfe-commits
mailing list