Skip to content

[concepts] out-of-line definition of constrained members is not accepted #49620

Closed
@Ivan171

Description

@Ivan171
Bugzilla Link 50276
Version trunk
OS Windows NT
CC @Ivan171,@zygoloid

Extended Description

$ cat utf.cpp

#include <concepts>

template <typename>
struct utf_t;

template <typename T>
    requires (std::is_same_v<T, char32_t>) ||
             (std::is_same_v<T, wchar_t> && sizeof(wchar_t) == sizeof(char32_t))
struct utf_t<T> {
  utf_t() {
  }

  template <typename Input>
  static auto length(Input begin, Input const end) -> unsigned;
};

template <typename T>
    requires (std::is_same_v<T, char32_t>) ||
             (std::is_same_v<T, wchar_t> && sizeof(wchar_t) == sizeof(char32_t))
template <typename Input>
inline auto utf_t<T>::length(Input begin, Input const end) -> unsigned {
  return 0;
}

$ clang++ -std=c++20 utf.cpp

utf.cpp:21:23: error: out-of-line definition of 'length' from class 'utf_t<type-parameter-0-0>' without definition
inline auto utf_t<T>::length(Input begin, Input const end) -> unsigned {
            ~~~~~~~~~~^
1 error generated.

No matter how you constrain it, it doesn't work: https://godbolt.org/z/qqaM89nTx

GCC compiles it without any error: https://godbolt.org/z/PM3seoYvW

Metadata

Metadata

Labels

bugzillaIssues migrated from bugzillac++20clang:frontendLanguage frontend issues, e.g. anything involving "Sema"conceptsC++20 concepts

Type

No type

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions