<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/59330>59330</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            clang fails to diagnose non-constexpr function call in return statement of constexpr member function
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          tmatheson-arm
      </td>
    </tr>
</table>

<pre>
    Example:
```c++
struct A { int f() const; };

struct B {
  A a;
  constexpr int should_error_but_will_not() const {
    return a.f(); // gcc will error here, clang will not
  }
  constexpr int does_error() const {
    constexpr int i = a.f(); // both error here
    return i;
  }
};
```
Here are the outputs from g++9, g++11, and clang-16:
```cpp
========== g++-9 -std=c++17 input.cpp ==========
        .file   "input.cpp"
../input.cpp: In member function ‘constexpr int B::should_error_but_will_not() const’:
../input.cpp:6:15: error: call to non-‘constexpr’ function ‘int A::f() const’
    6 |     return a.f(); // gcc will error here, clang will not
      |            ~~~^~
../input.cpp: In member function ‘constexpr int B::does_error() const’:
../input.cpp:9:26: error: call to non-‘constexpr’ function ‘int A::f() const’
    9 |     constexpr int i = a.f(); // both error here
      |                       ~~~^~
========== g++-11 -std=c++17 input.cpp ==========
        .file   "input.cpp"
../input.cpp: In member function ‘constexpr int B::should_error_but_will_not() const’:
../input.cpp:6:15: error: call to non-‘constexpr’ function ‘int A::f() const’
    6 |     return a.f(); // gcc will error here, clang will not
      |            ~~~^~
../input.cpp:1:16: note: ‘int A::f() const’ declared here
    1 | struct A { int f() const; };
      |                ^
../input.cpp: In member function ‘constexpr int B::does_error() const’:
../input.cpp:9:26: error: call to non-‘constexpr’ function ‘int A::f() const’
    9 |     constexpr int i = a.f(); // both error here
      |                       ~~~^~
../input.cpp:1:16: note: ‘int A::f() const’ declared here
    1 | struct A { int f() const; };
      |                ^
========== clang++-16 -std=c++17 input.cpp ==========
../input.cpp:9:19: error: constexpr variable 'i' must be initialized by a constant expression
    constexpr int i = a.f(); // both error here
                  ^   ~~~~~
../input.cpp:9:23: note: implicit use of 'this' pointer is only allowed within the evaluation of a call to a 'constexpr' member function
    constexpr int i = a.f(); // both error here
                      ^
1 error generated.
```

Clang _will_ successfully error if any of the following are done:
- make `a` global rather than a member
- `f()` is a non-member function
- make `should_error_but_will_not` a free function rather than a member function

</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzsV11vozgU_TXOy1UibAIJDzykk1a7v6K6wAW8a2xkm3a6D_3tKwNJmpbOdjTdkVY7iH4A9uHcc8-9NuicbDRRzpIblhxXOPjW2Nx36FtyRq_RdqvCVE_57VfsekUsPrDoyKIDS6PpLJm4Ced413k7lB4OwHY3ILWHmok9ExmURjvP4htguyOL59FXc8Kj-T7AAfA8CqbJ9LW3I6RrzaCqe7LW2Pti8PePUql7bfzLV70EA7DkB6sBNzOdkYi4Y-IOmrKEAAAjHrRkiYkvUCrUzfQgIM9Igfwip8qQmxi9T-J6hgQWHxcZFca3L9m8jkK-UOZM6ErWU2qmy9_IEqAl8C2BGXw_eAe1NR00U-qyEPD8P-fhAnU1KbDm6ULG-36-Ex-_cZ4g1xmsna9YfJytwncgdT_4Tdn38G2MS_Dh2NRSEQAwIc4ATIhp0GbDxN3ldnyA3zV01BVkoR506aXRwG4F20cs218n4yYEGR8-5KwTRHYW5s2bg2Y8CRQmS8QHKFEp8Aa00eu3JM6YC0wDv8PEr17mcdYoBbb7Ap9p-HCcMOfj-fmZJbfPnyb6cul8QOXwSKQ_X-XsrMgPV_Qbcd_T-YOVxvmvUvvflBoPP6P_tfFhYf6OQKCiUqGl6pUh-Ujh-1bxd43MkttfXeJndon_sEX-ocGNJXNqcumPNrlFk_Ds2iTnrD2glVgoAiZ2kokddIPzUBBILb1EJf-iCoonwGkOag9hHjknjf7E7d8b5ab0P7-X_NH58cvky65XspQeBkdg6hCQb6ULMfVGak8WpAOj1ROgUuaRKniUvpV63DrSA6o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