Bug 88600 - GCC rejects attributes on type aliases, while clang accepts them
Summary: GCC rejects attributes on type aliases, while clang accepts them
Status: NEW
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 9.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: rejects-valid
Depends on:
Blocks:
 
Reported: 2018-12-26 16:32 UTC by Jan Hubicka
Modified: 2019-01-02 17:53 UTC (History)
4 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2019-01-02 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jan Hubicka 2018-12-26 16:32:54 UTC
Compiling:

template <typename T> using V = __attribute__ ((__vector_size (8))) T;

with GCC leads to:

tt.C:1:69: warning: ignoring attributes applied to dependent type ‘T’ without an associated declaration [-Wattributes]
 template <typename T> using V = __attribute__ ((__vector_size (8))) T;
                                                                     ^

while clang produces type V which is vector of integers. This is used by templates in Skia library which I am not sure how to write w/o this construct:

    // These are __m256 and __m256i, but friendlier and strongly-typed.
    template <typename T> using V = T __attribute__((ext_vector_type(8)));
    using F   = V<float   >;
    using I32 = V< int32_t>;
    using U64 = V<uint64_t>;
    using U32 = V<uint32_t>;
    using U16 = V<uint16_t>;
    using U8  = V<uint8_t >;

I am not sure how to do the same in a way compatible with GCC.
Comment 1 Alexander Monakov 2018-12-26 17:40:31 UTC
Applying the attribute to V rather than T works:

template <typename T>
using V __attribute__ ((__vector_size (8))) = T;
Comment 2 Jan Hubicka 2018-12-26 18:09:49 UTC
> Applying the attribute to V rather than T works:
> 
> template <typename T>
> using V __attribute__ ((__vector_size (8))) = T;

Very cool, I did managed to work that out.  Should it work the clang way
too?
Comment 3 Martin Sebor 2019-01-02 17:53:32 UTC
The grammar implies the original form of the alias-declaration should be accepted with standard C++ attributes so I think it would make sense to accept it with GNU attributes as well:

  alias-declaration:
    using identifier attribute-specifier-seq opt = defining-type-id;

  defining-type-id:
    defining-type-specifier-seq abstract-declarator opt

  defining-type-specifier-seq:
    defining-type-specifier attribute-specifier-seq opt
    defining-type-specifier defining-type-specifier-seq

With that, I would expect the following two declarations to be equivalent:

  template <class T>
  using U = __attribute__ ((__vector_size__ (8))) T;

  template <class T>
  using V = [[gnu::vector_size (8)]] T;

Here GCC rejects both forms while Clang accepts the GNU form but (ironically) rejects the standard form.