Skip to content

Regression introduced with implementation of P2036R3 (assertion error) #65067

Closed as not planned
@alejandro-alvarez-sonarsource

Description

Hello,

Commit 93d7002 introduced a regression. A reproducing snippet:

template <typename T> T &declval() noexcept {}

template <typename T> struct FakeVoidToVoid {};

template <typename Func> inline auto call(Func &&func) { return func(); }

template <typename Func>
using NormalizedCallResult = FakeVoidToVoid<decltype(call(declval<Func>()))>;

template <typename T> class SemiFuture {
public:
  template <typename Func> auto then(Func &&func) {
    return and_then(wrapCB<T>(func));
  }

  template <typename Func> auto and_then(Func &&func) {
    using Result = NormalizedCallResult<Func>;
  }

protected:
  template <typename RawArg, typename Func> auto wrapCB(Func &&func) {
    return [func = func](auto... args) -> SemiFuture<decltype(func(args...))> {return {};};
  }
};

auto removeDocumentsInRange(SemiFuture<void> waitForActiveQueriesToComplete) {
  return waitForActiveQueriesToComplete.then([]() {});
}

This has been reduced from code coming from MongoDB.

Before 93d7002, the func in decltype(func(args...) would refer to the parameter func. After the commit, it would refer to the variable func introduced by the capture. It looks like other parts of the parser (i,e, TemplateInstantiator::TransformDecl) do not expect to find a VarDecl and fail to handle them.

This regression happens for C++14 and higher, even though "Change scope of lambda trailing-return-type" was introduced with C++23.

Metadata

Metadata

Assignees

No one assigned

    Labels

    clang:frontendLanguage frontend issues, e.g. anything involving "Sema"confirmedVerified by a second partyduplicateResolved as duplicateregression

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions