Updated patch according to Richard Smith's comments.
http://llvm-reviews.chandlerc.com/D2440
CHANGE SINCE LAST DIFF
http://llvm-reviews.chandlerc.com/D2440?vs=6180&id=6448#toc
Files:
include/clang/Parse/Parser.h
lib/Parse/ParseExpr.cpp
test/SemaCXX/expressions.cpp
Index: include/clang/Parse/Parser.h
===================================================================
--- include/clang/Parse/Parser.h
+++ include/clang/Parse/Parser.h
@@ -1788,6 +1788,7 @@
/// disambiguation will occur.
enum TentativeCXXTypeIdContext {
TypeIdInParens,
+ TypeIdUnambiguous,
TypeIdAsTemplateArgument
};
@@ -1806,6 +1807,16 @@
return isTypeIdInParens(isAmbiguous);
}
+ /// \brief Checks if the current tokens form type-id or expression.
+ /// It is similar to isTypeIdInParens but does not suppose that type-id
+ /// is in parenthesis.
+ bool isTypeIdUnambiguously() {
+ bool IsAmbiguous;
+ if (getLangOpts().CPlusPlus)
+ return isCXXTypeId(TypeIdUnambiguous, IsAmbiguous);
+ return isTypeSpecifierQualifier();
+ }
+
/// isCXXDeclarationStatement - C++-specialized function that disambiguates
/// between a declaration or an expression statement, when parsing function
/// bodies. Returns true for declaration, false for expression.
Index: lib/Parse/ParseExpr.cpp
===================================================================
--- lib/Parse/ParseExpr.cpp
+++ lib/Parse/ParseExpr.cpp
@@ -1492,8 +1492,7 @@
// pathenthesis around type name.
if (OpTok.is(tok::kw_sizeof) || OpTok.is(tok::kw___alignof) ||
OpTok.is(tok::kw_alignof) || OpTok.is(tok::kw__Alignof)) {
- bool isAmbiguousTypeId;
- if (isTypeIdInParens(isAmbiguousTypeId)) {
+ if (isTypeIdUnambiguously()) {
DeclSpec DS(AttrFactory);
ParseSpecifierQualifierList(DS);
Declarator DeclaratorInfo(DS, Declarator::TypeNameContext);
Index: test/SemaCXX/expressions.cpp
===================================================================
--- test/SemaCXX/expressions.cpp
+++ test/SemaCXX/expressions.cpp
@@ -118,3 +118,10 @@
(void)s1.foo();
(void)s2.foo();
}
+
+namespace pr16992 {
+ typedef int T;
+ unsigned getsz() {
+ return (sizeof T());
+ }
+}
Index: include/clang/Parse/Parser.h
===================================================================
--- include/clang/Parse/Parser.h
+++ include/clang/Parse/Parser.h
@@ -1788,6 +1788,7 @@
/// disambiguation will occur.
enum TentativeCXXTypeIdContext {
TypeIdInParens,
+ TypeIdUnambiguous,
TypeIdAsTemplateArgument
};
@@ -1806,6 +1807,16 @@
return isTypeIdInParens(isAmbiguous);
}
+ /// \brief Checks if the current tokens form type-id or expression.
+ /// It is similar to isTypeIdInParens but does not suppose that type-id
+ /// is in parenthesis.
+ bool isTypeIdUnambiguously() {
+ bool IsAmbiguous;
+ if (getLangOpts().CPlusPlus)
+ return isCXXTypeId(TypeIdUnambiguous, IsAmbiguous);
+ return isTypeSpecifierQualifier();
+ }
+
/// isCXXDeclarationStatement - C++-specialized function that disambiguates
/// between a declaration or an expression statement, when parsing function
/// bodies. Returns true for declaration, false for expression.
Index: lib/Parse/ParseExpr.cpp
===================================================================
--- lib/Parse/ParseExpr.cpp
+++ lib/Parse/ParseExpr.cpp
@@ -1492,8 +1492,7 @@
// pathenthesis around type name.
if (OpTok.is(tok::kw_sizeof) || OpTok.is(tok::kw___alignof) ||
OpTok.is(tok::kw_alignof) || OpTok.is(tok::kw__Alignof)) {
- bool isAmbiguousTypeId;
- if (isTypeIdInParens(isAmbiguousTypeId)) {
+ if (isTypeIdUnambiguously()) {
DeclSpec DS(AttrFactory);
ParseSpecifierQualifierList(DS);
Declarator DeclaratorInfo(DS, Declarator::TypeNameContext);
Index: test/SemaCXX/expressions.cpp
===================================================================
--- test/SemaCXX/expressions.cpp
+++ test/SemaCXX/expressions.cpp
@@ -118,3 +118,10 @@
(void)s1.foo();
(void)s2.foo();
}
+
+namespace pr16992 {
+ typedef int T;
+ unsigned getsz() {
+ return (sizeof T());
+ }
+}
_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits