'const void' is considered to be an incomplete type by clang 3.5.0

I tried to compile some Qt5 project with the latest clang-3.5.0 (rev.206727) and got this error:

../../../../../local/include/qt5/QtCore/qmetatype.h|1319 col 27| error: invalid application of 'sizeof' to an incomplete type 'const void'

        Q_STATIC_ASSERT_X(sizeof(T), "Type argument of

Q_DECLARE_METATYPE(T*) must be fully defined");

This message, as it is worded, isn't valid because 'const void' isn't 'incomplete'. This error was triggered by the templated class (template<typename T> struct IsPointerToTypeDerivedFromQObject<T*>) instantiated with the template argument T=const void.

clang-3.3 didn't have such issue.

Many Qt users will see this error, because this code is in a very common qt include file.

Yuri

From: "Yuri" <yuri@rawbw.com>
To: cfe-dev@cs.uiuc.edu
Sent: Monday, April 21, 2014 1:58:34 PM
Subject: [cfe-dev] 'const void' is considered to be an incomplete type by clang 3.5.0

I tried to compile some Qt5 project with the latest clang-3.5.0
(rev.206727) and got this error:

../../../../../local/include/qt5/QtCore/qmetatype.h|1319 col 27|
error:
invalid application of 'sizeof' to an incomplete type 'const void'
>> Q_STATIC_ASSERT_X(sizeof(T), "Type argument of
Q_DECLARE_METATYPE(T*) must be fully defined");

This message, as it is worded, isn't valid because 'const void' isn't
'incomplete'.

What do you mean? As I understand it, void is always incomplete. What do you expect sizeof(const void) to return?

-Hal

'incomplete' implies that it can be completed, and 'const void' can't be completed. So there are two different situations and this message doesn't differentiate between them.
The message should say "can't apply 'sizeof' to 'const void'" to be more clear.

Curiously, clang-3.3 thought that sizeof(const void) is 1.

Yuri

From: "Yuri" <yuri@rawbw.com>
To: "Hal Finkel" <hfinkel@anl.gov>
Cc: cfe-dev@cs.uiuc.edu
Sent: Monday, April 21, 2014 2:16:16 PM
Subject: Re: [cfe-dev] 'const void' is considered to be an incomplete type by clang 3.5.0

> What do you mean? As I understand it, void is always incomplete.
> What do you expect sizeof(const void) to return?

'incomplete' implies that it can be completed, and 'const void' can't
be
completed.

Perhaps, but 'incomplete' here is the correct technical term. 3.9.1 says, "The void type is an incomplete type that cannot be completed.".

So there are two different situations and this message
doesn't differentiate between them.
The message should say "can't apply 'sizeof' to 'const void'" to be
more
clear.

Curiously, clang-3.3 thought that sizeof(const void) is 1.

Interesting.

-Hal

Hmm, maybe this was the GNU 'arithmetic on void pointers' extension leaking
through?

The gnu arithmetic on void pointers extension explicitly says sizeof(void) == 1, no leaking required.

http://gcc.gnu.org/onlinedocs/gcc/Pointer-Arith.html

– Steve

It also says "In GNU C". The leaking would be this extension leaking into
C++ mode.

Yuri wrote:

I tried to compile some Qt5 project with the latest clang-3.5.0
(rev.206727) and got this error:

../../../../../local/include/qt5/QtCore/qmetatype.h|1319 col 27| error:
invalid application of 'sizeof' to an incomplete type 'const void'
>> Q_STATIC_ASSERT_X(sizeof(T), "Type argument of
Q_DECLARE_METATYPE(T*) must be fully defined");

FYI:

https://codereview.qt-project.org/#change,83568

Thanks,

Steve.