Bug 102748

Summary: static_assert on concept leads to undefined reference
Product: gcc Reporter: Raffael Casagrande <raffael>
Component: c++Assignee: Not yet assigned to anyone <unassigned>
Status: NEW ---    
Severity: normal CC: raffael, webrown.cpp
Priority: P3 Keywords: c++-lambda, link-failure
Version: 12.0   
Target Milestone: ---   
See Also: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102198
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99130
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109232
Host: Target:
Build: Known to work:
Known to fail: Last reconfirmed: 2021-10-15 00:00:00
Bug Depends on:    
Bug Blocks: 54367    

Description Raffael Casagrande 2021-10-14 15:37:11 UTC
Try to compile and link the following simple program with `-std=c++20`:
-----------------------------------
template <class RANGE, class CALLABLE>
auto ForEachGuided(RANGE&& range, CALLABLE&& c) {
  range.begin();
}

struct RandomAccessRangeAT {
  void begin() const noexcept;
};

template <class FE_SPACE_FACTORY>
concept FESpaceFactory = requires(const FE_SPACE_FACTORY& fe_space_factory,
                                  const RandomAccessRangeAT& range) {
  {fe_space_factory(range)};
};

int main() {
  auto fes_provider = [](auto&& range) {
    ForEachGuided(range, []() {});
  };
  static_assert(FESpaceFactory<decltype(fes_provider)>);
}
--------------------------------------

Compilation will work, but during linking we get the error message:
"undefined reference to `RandomAccessRangeAT::begin() const'"

As soon as we apply some optimization flags, the linking error vanishes.
Also clang doesn't have this problem...
Comment 1 Andrew Pinski 2021-10-15 00:16:01 UTC
Confirmed related to PR 99130.