Skip to content

[clang] diagnostic of not-yet-defined consteval function isn't great #68527

Open
@philnik777

Description

@philnik777
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.

Activity

added
clang:diagnosticsNew/improved warning or error message in Clang, but not in clang-tidy or static analyzer
on Oct 8, 2023
shafik

shafik commented on Oct 9, 2023

@shafik
Collaborator

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

shafik commented on Nov 14, 2023

@shafik
Collaborator
jwakely

jwakely commented on Nov 20, 2023

@jwakely
Contributor

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

tbaederr commented on Nov 21, 2023

@tbaederr
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

cor3ntin commented on Nov 27, 2023

@cor3ntin
Contributor
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    clang:diagnosticsNew/improved warning or error message in Clang, but not in clang-tidy or static analyzer

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @jwakely@cor3ntin@shafik@philnik777@tbaederr

        Issue actions

          [clang] diagnostic of not-yet-defined consteval function isn't great · Issue #68527 · llvm/llvm-project