Injected class name

Hi,

Why does clang refuse this case?

Looks like it still thinks that *p is opaque at the object definition, when it’s not.

class Class {

public:

Class *p;

int i;

Class(int a) : p(0), i(a) {}

};

const class Class &object = 0;

/*

$ clang -c injected.cpp

injected.cpp:7:29: error: cannot compile this global variable that binds reference to a non-lvalue yet

const class Class &object = 0;

^

1 error generated.

*/

As far as I understand, chapter 9 (paragraph 2) of the (C++03) standard allows you to do that. Other compilers, such as G++, understand it without problems.

Cheers,

–renato

Why does clang refuse this case?

$ clang -c injected.cpp

injected.cpp:7:29: error: cannot compile this global variable that binds
reference to a non-lvalue yet

const class Class &object = 0;

                            ^

1 error generated.

As far as I understand, chapter 9 (paragraph 2) of the (C++03) standard
allows you to do that. Other compilers, such as G++, understand it

without

problems.

I direct your attention to the word "yet" in the error message. In other
words, it's simply something that isn't yet implemented. Or perhaps it
would actually work, but we forgot to remove the error message.

Sebastian

I see, I thought the "yet" was about the type still being incomplete,
not unimplemented feature. :wink:

I'll play with it a bit...

cheers,
--renato