llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
28.11k stars 11.6k forks source link

Macro expansion yields "error: expected unqualified-id" with no source location at all #29054

Open llvmbot opened 8 years ago

llvmbot commented 8 years ago
Bugzilla Link 28680
Version trunk
OS All
Reporter LLVM Bugzilla Contributor
CC @DougGregor

Extended Description

no filename, no line number, no nothing, except:

error: expected unqualified-id

Checking on godbolt, it seems to be a regression between 3.7.1 and 3.8.

https://godbolt.org/g/7Duczj

class Foo { static const char * string; };

define MESSAGE_STUFF(type, string) \

const char * type::string = string;

MESSAGE_STUFF(Foo, "hello");

llvmbot commented 5 years ago
class Foo {
 static const char * string; 
};

#define MESSAGE_STUFF(type, string) \
    const char * type::string = string;

  MESSAGE_STUFF(Foo, "hello");

The original test case also still fails in the same manner.

llvmbot commented 5 years ago
class Foo {};
#define WHOOPS void Foo::&bar() {}
WHOOPS
llvmbot commented 5 years ago

I'm still seeing this on trunk. May have something to do with errors immediately after a '::'. Here's another test case exhibiting this behavior:

--

class Foo {};
#define WHOOPS void Foo::&bar() {}

WHOOPS

--

https://godbolt.org/z/Oisd-x

Also confirming on godbolt that I see this behavior for clang 7.0.0, 6.0.0, 5.0.0, 4.0.1, 4.0.0, 3.9.1, 3.9.0, 3.8.1, and 3.8.

3.7.1 indeed gives the proper error:

:5:1: error: expected unqualified-id

WHOOPS

^

:3:26: note: expanded from macro 'WHOOPS'

define WHOOPS void Foo::&bar() {}

                     ^

1 error generated.

--

Clang trunk error:

error: expected unqualified-id

1 error generated.

--

GCC 8.2 error:

:3:26: error: expected unqualified-id before '&' token

define WHOOPS void Foo::&bar() {}

                      ^

:5:1: note: in expansion of macro 'WHOOPS'

WHOOPS

^~

llvmbot commented 8 years ago

if you actually expand the macro by hand, you get a more sensible error message.