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] diagnostic of not-yet-defined consteval function isn't great #68527

Open
philnik777 opened this issue Oct 8, 2023 · 5 comments
Open
Labels
clang:diagnostics New/improved warning or error message in Clang, but not in clang-tidy or static analyzer

Comments

@philnik777
Copy link
Contributor

struct S {

  static bool func2() { return func(); }

  static consteval bool func() { return true; }
};

results in the diagnostic

<source>:4:32: error: call to consteval function 'S::func' is not a constant expression
    4 |   static bool func2() { return func(); }
      |                                ^
<source>:4:32: note: undefined function 'func' cannot be used in a constant expression
<source>:6:25: note: declared here
    6 |   static consteval bool func() { return true; }
      |                         ^
1 error generated.

The note is somewhat confusing IMO, since the consteval function is in fact defined. Something like consteval function that has not yet been defined cannot be used would be better, and an additional note consider moving the definition of `func` above `func2` would be really great.

@philnik777 philnik777 added the clang:diagnostics New/improved warning or error message in Clang, but not in clang-tidy or static analyzer label Oct 8, 2023
@shafik
Copy link
Collaborator

shafik commented Oct 9, 2023

I believe this is related to cwg1890, cwg2335, cwg1397 etc

At first it seems like expr.const p5.4:

an invocation of an undefined constexpr function;

but once we are in the body of member function we are in a complete class context and so then we should have a definition. All the issues I mentioned are various versions of that.

I posted to core and waiting for more feedback.

@shafik
Copy link
Collaborator

shafik commented Nov 14, 2023

See core discussion at: https://lists.isocpp.org/core/2023/10/14932.php

@jwakely
Copy link
Contributor

jwakely commented Nov 20, 2023

Is this why the following code fails with clang + libstdc++?

#include <string>
constexpr auto z  = std::string("", 0).size();

There's no consteval function here, but we get a similar undefined function '_M_construct<const char *>' cannot be used in a constant expression diagnostic about a member function defined outside the class body.

@tbaederr
Copy link
Contributor

Is this why the following code fails with clang + libstdc++?

Shouldn't be a problem I think? https://godbolt.org/z/vcbcKK1Ez works, unless you swap lines 10 and 12.

@cor3ntin
Copy link
Contributor

@jwakely see #73232

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:diagnostics New/improved warning or error message in Clang, but not in clang-tidy or static analyzer
Projects
None yet
Development

No branches or pull requests

5 participants