I accidentally found that the Clang compiler allows :
inline class AAA
{
};
in C++. What's this?
PS. I reported this to Clang mailing list cfe-dev@cs.uiuc.edu
, and now waiting for reply. I'll update this question by I'm informed.
I accidentally found that the Clang compiler allows :
inline class AAA
{
};
in C++. What's this?
PS. I reported this to Clang mailing list cfe-dev@cs.uiuc.edu
, and now waiting for reply. I'll update this question by I'm informed.
clang shouldn't allow this,
inline
can only be used in the declaration of functions, from ISO/IEC 14882:2003 7.1.2 [dcl.fct.spec] / 1 :inline
is one of three function-specifiers,virtual
andexplicit
being the others.As @MatthieuM notes, in the next version of C++ (C++0x), the
inline
keyword will also be allowed in namespace definitions (with different semantics toinline
as a function-specifier).I got an answer from Clang mailing list. It was a bug: http://llvm.org/bugs/show_bug.cgi?id=3941
However it looks already been fixed in recent build. Thanks anyway :)
Here's the conversation: http://lists.cs.uiuc.edu/pipermail/cfe-dev/2011-March/014207.html
It's allowed in case you wish to declare a function that returns an object of that class directly after the class' declaration, for example :
Also you should notice the compiler errors (or warnings) that appear in other illegal cases, such as declaring a variable instead of
A()
, also notice that the compiler states that it ignores theinline
keyword if you didn't declare any function.Hope that's helpful.
Edit : For The comment of Eonil
If you are talking about your code above in the question, then it's the same case as I see, the compiler will give you a warning :
'inline ' : ignored on left of 'AAA' when no variable is declared
However, if you use the code in my answer but replace
A()
with a variable,B
for example, it will generate a compiler error :'B' : 'inline' not permitted on data declarations
So we find that the compiler made no mistake with accepting such declarations, how about trying to write
inline double;
on its own? It will generate a warning :'inline ' : ignored on left of 'double' when no variable is declared
Now how about this declaration :
It gives no warnings or errors, it's exactly the same as :
since the precedence of
inline
is not important at all.The first code (in the whole answer) is similar to writing :
which is legal.
And, in other way, it can be written as :
You would be relieved if you see the first code (in the whole answer) written like :
But they are the same, since there is no importance for the precedence of
inline
.Hope it's clear and convincing.