Skip to content

consteval function not allowed in default argument to constexpr constructor #48230

@andreasfertig

Description

@andreasfertig
Bugzilla Link 48886
Version 11.0
OS All
CC @AaronBallman,@zygoloid

Extended Description

Hello,

the following valid code is currently rejected by Clang 11 and trunk (https://godbolt.org/z/645McM):

consteval int Fun() { return 0; }

struct Test {
  constexpr Test(int loc = Fun()) {}
};

Test t{};

The error is:

<source>:4:28: error: cannot take address of consteval function 'Fun' outside of an immediate invocation
  constexpr Test(int loc = Fun()) {}
                           ^
<source>:1:15: note: declared here
consteval int Fun() { return 0; }
              ^
1 error generated.
Compiler returned: 1

I had a brief communication with Richard Smith who confirmed that the code above is valid.

I assume this bug is similar to #47058

Best,

Andreas

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugzillaIssues migrated from bugzillac++20clang:frontendLanguage frontend issues, e.g. anything involving "Sema"confirmedVerified by a second partylibstdc++GNU libstdc++ C++ standard library

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions