[cfe-dev] [llvm-dev] Qualifiers not being discarded for atomic types while compiling with clang

Richard Smith via cfe-dev cfe-dev at lists.llvm.org
Fri Jun 9 15:17:40 PDT 2017


On 9 June 2017 at 00:21, Puneetha K via llvm-dev <llvm-dev at lists.llvm.org>
wrote:

> Hi,
> I am trying to compile the following:
>
> char * _Atomic restrict h;
>
> When compiled with -std=c11,clang gives error:
>          "restrict requires a pointer or reference (_Atomic(char*) is
> invalid)"
>

C11 6.7.3/5: "If other qualifiers appear along with the _Atomic qualifier
in a specifier-qualifier-list, the resulting type is the so-qualified
atomic type."

So the type of 'h' is 'restrict _Atomic(char*)', not '_Atomic(char
*restrict)'.

C11 6.7.3/2: "Types other than pointer types whose referenced type is an
object type shall not be restrict-qualified."

The type being restrict-qualified is _Atomic(char*), which is an atomic
type, not a pointer type, and thus this is ill-formed. (As it happens,
'_Atomic(char *restrict)' would also be ill-formed, due to 6.7.2.4/3: "The
type name in an atomic type specifier shall not refer to [...] a qualified
type.")


> while gcc compiles it successfully.
>
> Similarly, while trying to compile this
>
> extern int i;
> extern int _Atomic const ci;
> extern __typeof(ci) i;
>
> Clang gives error:
>
>           "Redeclaration of 'i' with a different type: 'typeof (ci)' (aka
> 'typeof _Atomic(int)') vs 'int' "
>
> while gcc compiles it successfully.
>
> This seems to be because clang probably considers Atomic int differently
> than int while gcc disregards these.
>
> Please suggest what should be the right behaviour in such cases.
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20170609/e3bd1477/attachment.html>


More information about the cfe-dev mailing list