Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
CalebAdrianXYZ opened this issue May 7, 2023 · 6 comments
Labels
clang:frontend Language frontend issues, e.g. anything involving "Sema"

Comments

@CalebAdrianXYZ
Copy link

CalebAdrianXYZ commented May 7, 2023

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

@EugeneZelenko EugeneZelenko added clang:frontend Language frontend issues, e.g. anything involving "Sema" and removed new issue labels May 7, 2023
@llvmbot
Copy link
Member

llvmbot commented May 7, 2023

@llvm/issue-subscribers-clang-frontend

@shafik
Copy link
Collaborator

shafik commented May 8, 2023

@cor3ntin is this #62462

@tbaederr
Copy link
Contributor

tbaederr commented May 8, 2023

In

const FunctionDecl *Definition = nullptr;
Stmt *Body = FD->getBody(Definition);
if (!CheckConstexprFunction(Info, E->getExprLoc(), FD, Definition, Body) ||
!HandleFunctionCall(E->getExprLoc(), Definition, This, Args, Call,
Body, Info, Result, ResultSlot))
return false;
both Body and Definition are nullptr, so the following CheckConstexprFunction diagnoses.

I don't know enough about the parsing here, are the bodies of static member functions only available later?

@cor3ntin
Copy link
Contributor

cor3ntin commented May 8, 2023

@cor3ntin is this #62462

Nope, but it might be #62224
Ie, we may be able to evaluate the argument too soon,
That or we don't do late parsing of template default arguments, which certainly would be surprising

@Fznamznon
Copy link
Contributor

That feels similar to #62224, although bar() is defined at the point we should be parsing baz(). Let me take a look.

@Fznamznon
Copy link
Contributor

https://reviews.llvm.org/D150108 that I was originally intending for #62224 helps here as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:frontend Language frontend issues, e.g. anything involving "Sema"
Projects
None yet
Development

No branches or pull requests

7 participants