Commit d462aa5a authored by Adam Czachorowski's avatar Adam Czachorowski
Browse files

[clang] Fix a nullptr dereference bug on invalid code

When working with invalid code, we would try to dereference a nullptr
while deducing template arguments in some dependend code operating on a
lambda with invalid return type.

Differential Revision: https://reviews.llvm.org/D95145
parent 68eee55c
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -4189,6 +4189,9 @@ TemplateDeclInstantiator::SubstFunctionType(FunctionDecl *D,
      for (unsigned OldIdx = 0, NumOldParams = OldProtoLoc.getNumParams();
           OldIdx != NumOldParams; ++OldIdx) {
        ParmVarDecl *OldParam = OldProtoLoc.getParam(OldIdx);
        if (!OldParam)
          return nullptr;

        LocalInstantiationScope *Scope = SemaRef.CurrentInstantiationScope;

        Optional<unsigned> NumArgumentsInExpansion;
+16 −0
Original line number Diff line number Diff line
// RUN: %clang -fsyntax-only -std=c++17 %s -Xclang -verify

// The important part is that we do not crash.

template<typename T> T declval();

template <typename T>
auto Call(T x) -> decltype(declval<T>()(0)) {} // expected-note{{candidate template ignored}}

class Status {};

void fun() {
  // The Status() (instead of Status) here used to cause a crash.
  Call([](auto x) -> Status() {}); // expected-error{{function cannot return function type 'Status ()}}
  // expected-error@-1{{no matching function for call to 'Call'}}
}