[cfe-dev] Newline vs space in C++ parsing
Nickolai Zeldovich
nickolai at csail.mit.edu
Fri Jan 18 10:01:59 PST 2013
I'm seeing surprising behavior in Clang 3.2 and 3.3-svn (as of a few days
ago), where newlines seem to be treated differently from spaces in parsing
C++ code. In particular, the following code compiles just fine:
% cat x.cc
struct s {};
struct s operator++(struct s a)
{ return a; }
% clang -c x.cc
%
but this version, with a newline instead of a space, generates an error:
% cat x.cc
struct s {};
struct s
operator++(struct s a)
{ return a; }
% clang -c x.cc
x.cc:3:9: error: expected ';' after struct
struct s
^
;
x.cc:4:1: error: C++ requires a type specifier for all declarations
operator++(struct s a)
^~~~~~~~
x.cc:5:10: error: no viable conversion from 'struct s' to 'int'
{ return a; }
^
3 errors generated.
%
g++ 4.7.2 accepts either variation, and I was expecting newlines and
spaces to be both treated as whitespace in C++. Is this a bug in Clang or
something more subtle?
Nickolai.
More information about the cfe-dev
mailing list