[cfe-commits] r108459 - in /cfe/trunk: lib/Parse/ParseTentative.cpp test/Parser/cxx-ambig-decl-expr-xfail.cpp test/Parser/cxx-ambig-decl-expr.cpp
Douglas Gregor
dgregor at apple.com
Thu Jul 15 14:05:01 PDT 2010
Author: dgregor
Date: Thu Jul 15 16:05:01 2010
New Revision: 108459
URL: http://llvm.org/viewvc/llvm-project?rev=108459&view=rev
Log:
When we're performing tentative parsing to determine whether the
parser is looking at a declaration or an expression, use a '=' to
conclude that we are parsing a declaration.
This is wrong. However, our previous approach of finding a comma after
the '=' is also wrong, because the ',' could be part of a
template-argument-list. So, for now we're going to use the same wrong
heuristic as GCC and Visual C++, because less real-world code is
likely to be broken this way. I've opened PR7655 to keep track of our
wrongness; note also the XFAIL'd test.
Fixes <rdar://problem/8193163>.
Added:
cfe/trunk/test/Parser/cxx-ambig-decl-expr-xfail.cpp (with props)
cfe/trunk/test/Parser/cxx-ambig-decl-expr.cpp (with props)
Modified:
cfe/trunk/lib/Parse/ParseTentative.cpp
Modified: cfe/trunk/lib/Parse/ParseTentative.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseTentative.cpp?rev=108459&r1=108458&r2=108459&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseTentative.cpp (original)
+++ cfe/trunk/lib/Parse/ParseTentative.cpp Thu Jul 15 16:05:01 2010
@@ -172,14 +172,6 @@
/// '{' '}'
///
Parser::TPResult Parser::TryParseInitDeclaratorList() {
- // GCC only examines the first declarator for disambiguation:
- // i.e:
- // int(x), ++x; // GCC regards it as ill-formed declaration.
- //
- // Comeau and MSVC will regard the above statement as correct expression.
- // Clang examines all of the declarators and also regards the above statement
- // as correct expression.
-
while (1) {
// declarator
TPResult TPR = TryParseDeclarator(false/*mayBeAbstract*/);
@@ -197,14 +189,15 @@
if (!SkipUntil(tok::r_paren))
return TPResult::Error();
} else if (Tok.is(tok::equal)) {
- // MSVC won't examine the rest of declarators if '=' is encountered, it
- // will conclude that it is a declaration.
- // Comeau and Clang will examine the rest of declarators.
- // Note that "int(x) = {0}, ++x;" will be interpreted as ill-formed
- // expression.
+ // MSVC and g++ won't examine the rest of declarators if '=' is
+ // encountered; they just conclude that we have a declaration.
+ // EDG parses the initializer completely, which is the proper behavior
+ // for this case.
//
- // Parse through the initializer-clause.
- SkipUntil(tok::comma, true/*StopAtSemi*/, true/*DontConsume*/);
+ // At present, Clang follows MSVC and g++, since the parser does not have
+ // the ability to parse an expression fully without recording the
+ // results of that parse.
+ return TPResult::True();
}
if (Tok.isNot(tok::comma))
Added: cfe/trunk/test/Parser/cxx-ambig-decl-expr-xfail.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Parser/cxx-ambig-decl-expr-xfail.cpp?rev=108459&view=auto
==============================================================================
--- cfe/trunk/test/Parser/cxx-ambig-decl-expr-xfail.cpp (added)
+++ cfe/trunk/test/Parser/cxx-ambig-decl-expr-xfail.cpp Thu Jul 15 16:05:01 2010
@@ -0,0 +1,16 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+// XFAIL: *
+struct X {
+ template<typename T> X(T);
+ X(int, int);
+
+ X operator()(int, int) const;
+};
+
+template<typename T, typename U> struct Y { };
+
+X *x;
+void f() {
+ int y = 0;
+ X (*x)(int(y), int(y)) = Y<int, float>(), ++y;
+}
Propchange: cfe/trunk/test/Parser/cxx-ambig-decl-expr-xfail.cpp
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: cfe/trunk/test/Parser/cxx-ambig-decl-expr-xfail.cpp
------------------------------------------------------------------------------
svn:keywords = Id
Propchange: cfe/trunk/test/Parser/cxx-ambig-decl-expr-xfail.cpp
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: cfe/trunk/test/Parser/cxx-ambig-decl-expr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Parser/cxx-ambig-decl-expr.cpp?rev=108459&view=auto
==============================================================================
--- cfe/trunk/test/Parser/cxx-ambig-decl-expr.cpp (added)
+++ cfe/trunk/test/Parser/cxx-ambig-decl-expr.cpp Thu Jul 15 16:05:01 2010
@@ -0,0 +1,10 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+struct X {
+ template<typename T, typename U>
+ static void f(int, int);
+};
+
+void f() {
+ void (*ptr)(int, int) = &X::f<int, int>;
+}
Propchange: cfe/trunk/test/Parser/cxx-ambig-decl-expr.cpp
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: cfe/trunk/test/Parser/cxx-ambig-decl-expr.cpp
------------------------------------------------------------------------------
svn:keywords = Id
Propchange: cfe/trunk/test/Parser/cxx-ambig-decl-expr.cpp
------------------------------------------------------------------------------
svn:mime-type = text/plain
More information about the cfe-commits
mailing list