Bug 94929 - [8 Regression] GCC 8 chokes on std::max in alignas
Summary: [8 Regression] GCC 8 chokes on std::max in alignas
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 8.4.0
: P3 normal
Target Milestone: 8.5
Assignee: Marek Polacek
URL:
Keywords: rejects-valid
Depends on:
Blocks:
 
Reported: 2020-05-02 22:34 UTC by David Seifert
Modified: 2020-05-04 17:37 UTC (History)
4 users (show)

See Also:
Host:
Target:
Build:
Known to work: 10.0, 11.0, 5.5.0, 9.2.0
Known to fail: 6.5.0, 7.5.0, 8.4.0
Last reconfirmed: 2020-05-03 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description David Seifert 2020-05-02 22:34:54 UTC
The following snippet

  #include <algorithm>

  struct One {};
  struct Two {};
  struct Foo { alignas(std::max(alignof(One), alignof(Two))) char value; };

compiles fine in GCC 9.3, but in GCC 8.4 fails with

test.cpp:5:65: error: requested alignment is not an integer constant
 struct Foo { alignas(std::max(alignof(One), alignof(Two))) char value; };
                                                                 ^~~~~
Comment 1 Jonathan Wakely 2020-05-03 08:44:43 UTC
.

*** This bug has been marked as a duplicate of bug 90736 ***
Comment 2 Jonathan Wakely 2020-05-03 08:49:47 UTC
Hmm, although this was fixed for gcc 9.2 by the patch for PR 90736 it seems to be a different root cause. This compiled with GCC 5 but not 6, 7 or 8:

template<typename T>
constexpr const T& max(const T& a, const T& b) { return a < b ? b : a; }

struct One {};
struct Two {};
struct Foo { alignas(max(alignof(One), alignof(Two))) char value; };

This regressed with r230365, "Merge C++ delayed folding branch."

Marek, looks like backporting r272219 would fix this.
Comment 3 Marek Polacek 2020-05-04 15:12:45 UTC
I'm going to backport the fix to 8 if it passes the usual testing.
Comment 4 Marek Polacek 2020-05-04 17:28:30 UTC
Done in r8-10235-gf6965321b1c00bfb2b9c8407df56bcf38f096088.
Comment 5 David Seifert 2020-05-04 17:28:49 UTC
(In reply to Marek Polacek from comment #3)
> I'm going to backport the fix to 8 if it passes the usual testing.

Hi Marek,
could you also test the inlined code. Defining some const and then using it alignas worked previously, the problem comes from doing all of it in alignas().
Comment 6 Marek Polacek 2020-05-04 17:37:25 UTC
(In reply to David Seifert from comment #5)
> (In reply to Marek Polacek from comment #3)
> > I'm going to backport the fix to 8 if it passes the usual testing.
> 
> Hi Marek,
> could you also test the inlined code. Defining some const and then using it
> alignas worked previously, the problem comes from doing all of it in
> alignas().

Both the original testcase in this PR and the test in Comment 2 now compile even with GCC 8.