Skip to content

[clang, trunk, c++11] Clang rejects NTTP defaulted value invoking static constexpr member function within class #62596

@CalebAdrianXYZ

Description

@CalebAdrianXYZ

Given the following C++11 code:

// minimal reproducible example, oversimplified code
struct foo {
    static constexpr bool bar() {
        return true;
    }

    template<bool B = bar()> // <-- clang has issue with this
    static constexpr bool baz() {
        return true;
    }
};
static_assert(foo::baz(), "");

GCC, MSVC, ICC, and NVC++ all compile this code successfully, but Clang (trunk) produces the following diagnostic output:

<source>:7:23: error: non-type template argument is not a constant expression
    template<bool B = bar()> // <-- clang has issue with this
                      ^~~~~
<source>:7:23: note: undefined function 'bar' cannot be used in a constant expression
<source>:3:27: note: declared here
    static constexpr bool bar() {
                          ^
<source>:12:15: error: no matching function for call to 'baz'
static_assert(foo::baz(), "");
              ^~~~~~~~
2 errors generated.
Compiler returned: 1

Corresponding CE link: https://godbolt.org/z/4Md1b5o8r

Metadata

Metadata

Assignees

No one assigned

    Labels

    clang:frontendLanguage frontend issues, e.g. anything involving "Sema"

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions