Bug 121855 - Diagnostic for not-a-constant-expression has no information
Summary: Diagnostic for not-a-constant-expression has no information
Status: RESOLVED DUPLICATE of bug 102262
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 15.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: diagnostic
Depends on:
Blocks: constexpr
  Show dependency treegraph
 
Reported: 2025-09-08 14:18 UTC by Barry Revzin
Modified: 2025-09-08 16:30 UTC (History)
0 users

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2025-09-08 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Barry Revzin 2025-09-08 14:18:13 UTC
This example:

struct S {
    int x = 42;
    /* not constexpr */ ~S() { }
};

consteval auto make() -> S { return S(); }

int main() {
    S s = make();
}

When compiled with gcc 15.2 -std=c++26 produces this diagnostic:

<source>: In function 'int main()':
<source>:10:15: error: call to consteval function 'make()' is not a constant expression
   10 |     S s = make();
      |           ~~~~^~
<source>:10:15: error: 'consteval S make()' called in a constant expression
<source>:7:16: note: 'consteval S make()' is not usable as a 'constexpr' function because:
    7 | consteval auto make() -> S { return S(); }
      |                ^~~~

It's not usable as a constexpr function because... why? Can we get a hint?
Comment 1 Drea Pinski 2025-09-08 16:30:41 UTC
Dup.

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