Bug 102748 - static_assert on concept leads to undefined reference
Summary: static_assert on concept leads to undefined reference
Status: NEW
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 12.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: c++-lambda, link-failure
Depends on:
Blocks: lambdas
  Show dependency treegraph
 
Reported: 2021-10-14 15:37 UTC by Raffael Casagrande
Modified: 2023-03-22 14:41 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2021-10-15 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
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.