Skip to content

Clang reports an undefined function that has been defined #73232

Open
@tbaederr

Description

@tbaederr

Not sure how to title this properly.

The original reproducer is just:

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

with libstdc++.

Using cvise, I get:

template <typename _CharT>
struct basic_string {
  constexpr void _M_construct();

  constexpr basic_string() {
    _M_construct();
  }

};


basic_string<char *> a;


template <typename _CharT>
constexpr void basic_string<_CharT>::_M_construct(){}

constexpr basic_string<char*> z{};

https://godbolt.org/z/7PzreExcf

Clang's output is:

<source>:18:16: error: constexpr variable 'z' must be initialized by a constant expression
   18 | constexpr auto z = basic_string<char *>();
      |                ^   ~~~~~~~~~~~~~~~~~~~~~~
<source>:6:5: note: undefined function '_M_construct' cannot be used in a constant expression
    6 |     _M_construct();
      |     ^
<source>:18:20: note: in call to 'basic_string()'
   18 | constexpr basic_string<char*> z{}
      |                    ^~~~~~~~~~~~~~~~~~~~~~
<source>:3:18: note: declared here
    3 |   constexpr void _M_construct();
      |                  ^

The problem vanishes if a is commented out, or if basic_string is not a template anymore.

Metadata

Metadata

Labels

clang:frontendLanguage frontend issues, e.g. anything involving "Sema"confirmedVerified by a second partyrejects-valid

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions