public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/94569] New: alignas(object) with a weaker (smaller) alignment than the alignas(type) of it's type compiles, inconsistent with the C++ standard
@ 2020-04-12 20:34 sinbal2l at gmail dot com
  2020-04-13  1:25 ` [Bug c++/94569] " richard-gccbugzilla at metafoo dot co.uk
                   ` (10 more replies)
  0 siblings, 11 replies; 12+ messages in thread
From: sinbal2l at gmail dot com @ 2020-04-12 20:34 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 94569
           Summary: alignas(object) with a weaker (smaller) alignment than
                    the alignas(type) of it's type compiles, inconsistent
                    with the C++ standard
           Product: gcc
           Version: 10.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: sinbal2l at gmail dot com
  Target Milestone: ---

The standard specifies:

>From the standard: [9.12.2 Alignment specifier, section 6, pg 226]

If the defining declaration of an entity has an alignment-specifier, any
non-defining declaration of that entity shall either specify equivalent
alignment or have no alignment-specifier. Conversely, if any declaration of an
entity has an alignment-specifier, every defining declaration of that entity
shall specify an equivalent alignment. 

But on the latest revision, this compiles:

typedef struct alignas(32){
    int i;
}U; 

int main() {
    alignas(16) U my_u;     // alignas(obj) of a weaker alignment than the
type.

    cout << "alignof(my_u): " << alignof(my_u) << endl;
    cout << "alignof (decltype(my_u))" << alignof (decltype(my_u)) << endl;
}

https://godbolt.org/z/2uNAag 

P.S. thank you very much for doing such a great job!

^ permalink raw reply	[flat|nested] 12+ messages in thread

* [Bug c++/94569] alignas(object) with a weaker (smaller) alignment than the alignas(type) of it's type compiles, inconsistent with the C++ standard
  2020-04-12 20:34 [Bug c++/94569] New: alignas(object) with a weaker (smaller) alignment than the alignas(type) of it's type compiles, inconsistent with the C++ standard sinbal2l at gmail dot com
@ 2020-04-13  1:25 ` richard-gccbugzilla at metafoo dot co.uk
  2020-04-13  2:19 ` sinbal2l at gmail dot com
                   ` (9 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: richard-gccbugzilla at metafoo dot co.uk @ 2020-04-13  1:25 UTC (permalink / raw)
  To: gcc-bugs

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

Richard Smith <richard-gccbugzilla at metafoo dot co.uk> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |richard-gccbugzilla@metafoo
                   |                            |.co.uk

--- Comment #1 from Richard Smith <richard-gccbugzilla at metafoo dot co.uk> ---
I believe the particular rule that is violated by this example is
[dcl.align]p5:

"The combined effect of all alignment-specifiers in a declaration shall not
specify an alignment that is less strict than the alignment that would be
required for the entity being declared if all alignment-specifiers appertaining
to that entity were omitted."

^ permalink raw reply	[flat|nested] 12+ messages in thread

* [Bug c++/94569] alignas(object) with a weaker (smaller) alignment than the alignas(type) of it's type compiles, inconsistent with the C++ standard
  2020-04-12 20:34 [Bug c++/94569] New: alignas(object) with a weaker (smaller) alignment than the alignas(type) of it's type compiles, inconsistent with the C++ standard sinbal2l at gmail dot com
  2020-04-13  1:25 ` [Bug c++/94569] " richard-gccbugzilla at metafoo dot co.uk
@ 2020-04-13  2:19 ` sinbal2l at gmail dot com
  2020-04-14  7:00 ` rguenth at gcc dot gnu.org
                   ` (8 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: sinbal2l at gmail dot com @ 2020-04-13  2:19 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Inbal Levi <sinbal2l at gmail dot com> ---
Yes, you're probably right, got the wrong one.
Thanks!

^ permalink raw reply	[flat|nested] 12+ messages in thread

* [Bug c++/94569] alignas(object) with a weaker (smaller) alignment than the alignas(type) of it's type compiles, inconsistent with the C++ standard
  2020-04-12 20:34 [Bug c++/94569] New: alignas(object) with a weaker (smaller) alignment than the alignas(type) of it's type compiles, inconsistent with the C++ standard sinbal2l at gmail dot com
  2020-04-13  1:25 ` [Bug c++/94569] " richard-gccbugzilla at metafoo dot co.uk
  2020-04-13  2:19 ` sinbal2l at gmail dot com
@ 2020-04-14  7:00 ` rguenth at gcc dot gnu.org
  2020-04-14  7:32 ` richard-gccbugzilla at metafoo dot co.uk
                   ` (7 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: rguenth at gcc dot gnu.org @ 2020-04-14  7:00 UTC (permalink / raw)
  To: gcc-bugs

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

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |accepts-invalid

--- Comment #3 from Richard Biener <rguenth at gcc dot gnu.org> ---
But isn't the alignas(32) also "appertaining to that entity"?

^ permalink raw reply	[flat|nested] 12+ messages in thread

* [Bug c++/94569] alignas(object) with a weaker (smaller) alignment than the alignas(type) of it's type compiles, inconsistent with the C++ standard
  2020-04-12 20:34 [Bug c++/94569] New: alignas(object) with a weaker (smaller) alignment than the alignas(type) of it's type compiles, inconsistent with the C++ standard sinbal2l at gmail dot com
                   ` (2 preceding siblings ...)
  2020-04-14  7:00 ` rguenth at gcc dot gnu.org
@ 2020-04-14  7:32 ` richard-gccbugzilla at metafoo dot co.uk
  2020-04-14 10:46 ` redi at gcc dot gnu.org
                   ` (6 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: richard-gccbugzilla at metafoo dot co.uk @ 2020-04-14  7:32 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from Richard Smith <richard-gccbugzilla at metafoo dot co.uk> ---
(In reply to Richard Biener from comment #3)
> But isn't the alignas(32) also "appertaining to that entity"?

No. The alignas(32) appertains to the struct. This is specified in [class]/2:
"The optional attribute-specifier-seq appertains to the class".

^ permalink raw reply	[flat|nested] 12+ messages in thread

* [Bug c++/94569] alignas(object) with a weaker (smaller) alignment than the alignas(type) of it's type compiles, inconsistent with the C++ standard
  2020-04-12 20:34 [Bug c++/94569] New: alignas(object) with a weaker (smaller) alignment than the alignas(type) of it's type compiles, inconsistent with the C++ standard sinbal2l at gmail dot com
                   ` (3 preceding siblings ...)
  2020-04-14  7:32 ` richard-gccbugzilla at metafoo dot co.uk
@ 2020-04-14 10:46 ` redi at gcc dot gnu.org
  2020-05-10  6:29 ` sinbal2l at gmail dot com
                   ` (5 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: redi at gcc dot gnu.org @ 2020-04-14 10:46 UTC (permalink / raw)
  To: gcc-bugs

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

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
     Ever confirmed|0                           |1
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2020-04-14

^ permalink raw reply	[flat|nested] 12+ messages in thread

* [Bug c++/94569] alignas(object) with a weaker (smaller) alignment than the alignas(type) of it's type compiles, inconsistent with the C++ standard
  2020-04-12 20:34 [Bug c++/94569] New: alignas(object) with a weaker (smaller) alignment than the alignas(type) of it's type compiles, inconsistent with the C++ standard sinbal2l at gmail dot com
                   ` (4 preceding siblings ...)
  2020-04-14 10:46 ` redi at gcc dot gnu.org
@ 2020-05-10  6:29 ` sinbal2l at gmail dot com
  2020-07-02  8:47 ` redi at gcc dot gnu.org
                   ` (4 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: sinbal2l at gmail dot com @ 2020-05-10  6:29 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #5 from Inbal Levi <sinbal2l at gmail dot com> ---
Stumbled across another rule which might be relevant here is:

[basic.align/1]

[...] An object type imposes an alignment requirement on every object of that
type; stricter alignment can be requested using the alignment specifier
(9.12.2).

Inherited from the C standard, which results in an error for the following
code:

#include <stdio.h>
typedef struct U U;
struct U {
} __attribute__((aligned (32))); 

int main() {
    _Alignas(16) U my_u;     // alignas(obj) of a weaker alignment than the
type.
}

https://godbolt.org/z/tdEJgo

^ permalink raw reply	[flat|nested] 12+ messages in thread

* [Bug c++/94569] alignas(object) with a weaker (smaller) alignment than the alignas(type) of it's type compiles, inconsistent with the C++ standard
  2020-04-12 20:34 [Bug c++/94569] New: alignas(object) with a weaker (smaller) alignment than the alignas(type) of it's type compiles, inconsistent with the C++ standard sinbal2l at gmail dot com
                   ` (5 preceding siblings ...)
  2020-05-10  6:29 ` sinbal2l at gmail dot com
@ 2020-07-02  8:47 ` redi at gcc dot gnu.org
  2020-07-02 10:25 ` sinbal2l at gmail dot com
                   ` (3 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: redi at gcc dot gnu.org @ 2020-07-02  8:47 UTC (permalink / raw)
  To: gcc-bugs

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

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |DUPLICATE
             Status|NEW                         |RESOLVED

--- Comment #6 from Jonathan Wakely <redi at gcc dot gnu.org> ---
This seems like another dup of PR 65685

*** This bug has been marked as a duplicate of bug 65685 ***

^ permalink raw reply	[flat|nested] 12+ messages in thread

* [Bug c++/94569] alignas(object) with a weaker (smaller) alignment than the alignas(type) of it's type compiles, inconsistent with the C++ standard
  2020-04-12 20:34 [Bug c++/94569] New: alignas(object) with a weaker (smaller) alignment than the alignas(type) of it's type compiles, inconsistent with the C++ standard sinbal2l at gmail dot com
                   ` (6 preceding siblings ...)
  2020-07-02  8:47 ` redi at gcc dot gnu.org
@ 2020-07-02 10:25 ` sinbal2l at gmail dot com
  2020-07-02 10:33 ` sinbal2l at gmail dot com
                   ` (2 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: sinbal2l at gmail dot com @ 2020-07-02 10:25 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #7 from Inbal Levi <sinbal2l at gmail dot com> ---
Not exactly.

94594 is talking about object's members impose their alignment on the object's
type, whether this bug is talking about object type imposes its alignment on
every object of that type (notice that in the example here, unlike the one on
94594, there's no alignment of the members). (this restriction is located at: 

  [basic.align/1]

  [...] An object type imposes an alignment requirement on every object of that 
  type; stricter alignment can be requested using the alignment specifier.

as posted below in the comments, unfortunately, since I couldn't edit the bug)

(Though, since posting that bug, I realized that though the restriction should
hold, the querying part, which is alignof(object), should first be qualified in
the standard. There's a paper: P2152 :) )

^ permalink raw reply	[flat|nested] 12+ messages in thread

* [Bug c++/94569] alignas(object) with a weaker (smaller) alignment than the alignas(type) of it's type compiles, inconsistent with the C++ standard
  2020-04-12 20:34 [Bug c++/94569] New: alignas(object) with a weaker (smaller) alignment than the alignas(type) of it's type compiles, inconsistent with the C++ standard sinbal2l at gmail dot com
                   ` (7 preceding siblings ...)
  2020-07-02 10:25 ` sinbal2l at gmail dot com
@ 2020-07-02 10:33 ` sinbal2l at gmail dot com
  2020-07-02 13:06 ` redi at gcc dot gnu.org
  2020-07-02 14:35 ` sinbal2l at gmail dot com
  10 siblings, 0 replies; 12+ messages in thread
From: sinbal2l at gmail dot com @ 2020-07-02 10:33 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #8 from Inbal Levi <sinbal2l at gmail dot com> ---
See here: https://bugs.llvm.org/show_bug.cgi?id=45890

^ permalink raw reply	[flat|nested] 12+ messages in thread

* [Bug c++/94569] alignas(object) with a weaker (smaller) alignment than the alignas(type) of it's type compiles, inconsistent with the C++ standard
  2020-04-12 20:34 [Bug c++/94569] New: alignas(object) with a weaker (smaller) alignment than the alignas(type) of it's type compiles, inconsistent with the C++ standard sinbal2l at gmail dot com
                   ` (8 preceding siblings ...)
  2020-07-02 10:33 ` sinbal2l at gmail dot com
@ 2020-07-02 13:06 ` redi at gcc dot gnu.org
  2020-07-02 14:35 ` sinbal2l at gmail dot com
  10 siblings, 0 replies; 12+ messages in thread
From: redi at gcc dot gnu.org @ 2020-07-02 13:06 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #9 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Both bugs are violations of [dcl.align] p5 though. The bug is not that GCC
doesn't follow [basic.align] p1 (it does) but that it allows alignas to weaken
the alignment later. GCC should not allow alignas to weaken alignment on any
declaration, whether a class declaration or variable declaration, and that's PR
65685. I've added a more complete testcase there, which includes alignas on
object declarations.

^ permalink raw reply	[flat|nested] 12+ messages in thread

* [Bug c++/94569] alignas(object) with a weaker (smaller) alignment than the alignas(type) of it's type compiles, inconsistent with the C++ standard
  2020-04-12 20:34 [Bug c++/94569] New: alignas(object) with a weaker (smaller) alignment than the alignas(type) of it's type compiles, inconsistent with the C++ standard sinbal2l at gmail dot com
                   ` (9 preceding siblings ...)
  2020-07-02 13:06 ` redi at gcc dot gnu.org
@ 2020-07-02 14:35 ` sinbal2l at gmail dot com
  10 siblings, 0 replies; 12+ messages in thread
From: sinbal2l at gmail dot com @ 2020-07-02 14:35 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #10 from Inbal Levi <sinbal2l at gmail dot com> ---
Actually, you're right about the origin being [dcl.align]p5 here too, though
the test cases are different. 
Thanks.

^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2020-07-02 14:35 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-04-12 20:34 [Bug c++/94569] New: alignas(object) with a weaker (smaller) alignment than the alignas(type) of it's type compiles, inconsistent with the C++ standard sinbal2l at gmail dot com
2020-04-13  1:25 ` [Bug c++/94569] " richard-gccbugzilla at metafoo dot co.uk
2020-04-13  2:19 ` sinbal2l at gmail dot com
2020-04-14  7:00 ` rguenth at gcc dot gnu.org
2020-04-14  7:32 ` richard-gccbugzilla at metafoo dot co.uk
2020-04-14 10:46 ` redi at gcc dot gnu.org
2020-05-10  6:29 ` sinbal2l at gmail dot com
2020-07-02  8:47 ` redi at gcc dot gnu.org
2020-07-02 10:25 ` sinbal2l at gmail dot com
2020-07-02 10:33 ` sinbal2l at gmail dot com
2020-07-02 13:06 ` redi at gcc dot gnu.org
2020-07-02 14:35 ` sinbal2l at gmail dot com

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).