r199284 - Fixed error recovery if sizeof is used without parenthesis
Serge Pavlov
sepavloff at gmail.com
Tue Jan 14 17:53:39 PST 2014
Author: sepavloff
Date: Tue Jan 14 19:53:39 2014
New Revision: 199284
URL: http://llvm.org/viewvc/llvm-project?rev=199284&view=rev
Log:
Fixed error recovery if sizeof is used without parenthesis
Changes made in r192200 fixed PR16992, which requested fixit suggesting
parenthesis if sizeof is followed by type-id. However expression in form
T() followed by ')' was incorrectly considered as a type-id if 'T' is
typedef name. This change fixes this case.
Differential Revision: http://llvm-reviews.chandlerc.com/D2440
Modified:
cfe/trunk/include/clang/Parse/Parser.h
cfe/trunk/lib/Parse/ParseExpr.cpp
cfe/trunk/test/SemaCXX/expressions.cpp
Modified: cfe/trunk/include/clang/Parse/Parser.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Parse/Parser.h?rev=199284&r1=199283&r2=199284&view=diff
==============================================================================
--- cfe/trunk/include/clang/Parse/Parser.h (original)
+++ cfe/trunk/include/clang/Parse/Parser.h Tue Jan 14 19:53:39 2014
@@ -1788,6 +1788,7 @@ private:
/// disambiguation will occur.
enum TentativeCXXTypeIdContext {
TypeIdInParens,
+ TypeIdUnambiguous,
TypeIdAsTemplateArgument
};
@@ -1806,6 +1807,16 @@ private:
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.
Modified: cfe/trunk/lib/Parse/ParseExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseExpr.cpp?rev=199284&r1=199283&r2=199284&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseExpr.cpp (original)
+++ cfe/trunk/lib/Parse/ParseExpr.cpp Tue Jan 14 19:53:39 2014
@@ -1492,8 +1492,7 @@ Parser::ParseExprAfterUnaryExprOrTypeTra
// 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);
Modified: cfe/trunk/test/SemaCXX/expressions.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/expressions.cpp?rev=199284&r1=199283&r2=199284&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/expressions.cpp (original)
+++ cfe/trunk/test/SemaCXX/expressions.cpp Tue Jan 14 19:53:39 2014
@@ -118,3 +118,10 @@ void test3() {
(void)s1.foo();
(void)s2.foo();
}
+
+namespace pr16992 {
+ typedef int T;
+ unsigned getsz() {
+ return (sizeof T());
+ }
+}
More information about the cfe-commits
mailing list