https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69065

            Bug ID: 69065
           Summary: [C++11] multiple alignas specifiers
           Product: gcc
           Version: 5.3.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: kukyakya at gmail dot com
  Target Milestone: ---

http://en.cppreference.com/w/cpp/language/alignas (quoting it since I don't
have the C++11 standard documents now) states that `alignas` can be used in the
form of `alignas(pack...)`, but both g++ and clang++ fail to compile it.

    struct alignas(int, double) test
    { };

So I tried to use multiple `alignas` specifiers, but got unexpected results.

    #include <iostream>

    // struct alignas(int, double) test
    // { };

    struct alignas(int) alignas(double) test1 { };
    struct alignas(double) alignas(int) test2 { };

    int main()
    {
      std::cout << "alignof(int) is " << alignof(int) << std::endl;
      std::cout << "alignof(double) is " << alignof(double) << std::endl;
      // std::cout << "alignof(test) is " << alignof(test) << std::endl;
      std::cout << "alignof(test1) is " << alignof(test1) << std::endl;
      std::cout << "alignof(test2) is " << alignof(test2) << std::endl;
    }

    alignof(int) is 4
    alignof(double) is 8
    alignof(test1) is 8
    alignof(test2) is 4

With clang++ I got

    alignof(int) is 4
    alignof(double) is 8
    alignof(test1) is 8
    alignof(test2) is 8

I'm not sure if it's okay to give multiple `alignas` specifiers, but I think it
should have the strictest alignment if it's okay. G++ seems to apply only the
latest `alignas` specifier.

Reply via email to