[PATCH] Implement transformations of non-capturing nested lambdas.

Faisal Vali faisalv at yahoo.com
Mon Sep 30 22:59:33 PDT 2013



================
Comment at: lib/Sema/SemaTemplateInstantiate.cpp:951
@@ +950,3 @@
+                                                          Innermost.size()),
+                                              /*InsertPos=*/0);
+#endif
----------------
Doug Gregor wrote:
> This is turning the call operator into a specialization of the old call operator template, which isn't quite right. We want to establish that NewCallOperatorTemplate was instantiated from the member template OldCallOperatorTemplate using RedeclarableTemplateDecl::setInstantiatedFromMemberTemplate(). See RedeclarableTemplateDecl::getInstantiatedFromMemberTemplate() for an example of how this method works.
Ok so I tried the following:
NewCallOperatorTemplate->setInstantiatedFromMemberTemplate(
                                                      OldCallOperatorTemplate);
But ended up with a new crash in the code below on line ####
[Am currently investigating this...]
struct X {
  static void foo(double d) { } 
  auto test() {
    auto L = [](auto a) {
      print("a = ", a, "\n");
      foo(a);
      return [](decltype(a) b) {
        foo(b);
        foo(sizeof(a) + sizeof(b));
        return [](auto ... c) {
          print("c = ", c ..., "\n");
          foo(decltype(b){});
          foo(sizeof(decltype(a)*) + sizeof(decltype(b)*));
          return [](decltype(c) ... d) ->decltype(a) { //expected-note{{candidate}}
            print("d = ", d ..., "\n");
            foo(decltype(b){});
            foo(sizeof(decltype(a)*) + sizeof(decltype(b)*));
            return decltype(a){};
          };
        };
      };
    };
    return L;
  }
};
  X x;
  auto L = x.test();
  L('4');
  auto M = L('3');
  M('a');
  auto N = M('x');
  auto O = N("\n3 = ", 3, "\n6.14 = ", 6.14, "\n4'123'456 = ", 4'123'456); <-- this line ####

CRASH:

 s s e r t i o n   f a i l e d :   N u m A r g u m e n t s I n E x p a n s i o n   & &   " s h o u l d   o n l y   b e
 c a l l e d   w h e n   a l l   t e m p l a t e   a r g u m e n t s   a r e   k n o w n " ,   f i l e   . . \ . . \ .
 \ . . \ . . \ l l v m \ t o o l s \ c l a n g \ l i b \ S e m a \ S e m a T e m p l a t e I n s t a n t i a t e D e c
 . c p p ,   l i n e   2 8 2 2
Stack dump:
.      Program arguments: F:/clang-trunk/build/bin/Debug/clang.EXE -cc1 -internal-isystem F:\clang-trunk\build\bin\Debu
\..\lib\clang\3.4\include -std=c++1y -verify -fsyntax-only -fblocks -emit-llvm -o - F:\clang-trunk\llvm\tools\clang\tes
\semacxx\cxx1y-generic-lambdas.cpp
.      F:\clang-trunk\llvm\tools\clang\test\semacxx\cxx1y-generic-lambdas.cpp:322:73: current parser token ')'
.      F:\clang-trunk\llvm\tools\clang\test\semacxx\cxx1y-generic-lambdas.cpp:116:1: parsing namespace 'nested_non_capt
ring_lambda_tests'
.      F:\clang-trunk\llvm\tools\clang\test\semacxx\cxx1y-generic-lambdas.cpp:118:12: parsing function body 'test'
.      F:\clang-trunk\llvm\tools\clang\test\semacxx\cxx1y-generic-lambdas.cpp:118:12: in compound statement ('{}')
.      F:\clang-trunk\llvm\tools\clang\test\semacxx\cxx1y-generic-lambdas.cpp:290:1: in compound statement ('{}')
x56CA89EB (0x0000000A 0x00000000 0x04AB906C 0x56D76237), _get_pgmptr() + 0x21B bytes(s)
x56D84F2E (0x04AB90C0 0x04AB9080 0x00000000 0x04AB89C0), abort() + 0x1E bytes(s)
x56D76237 (0x03BEB080 0x03BEAFE8 0x00000B06 0x04AB9360), _wassert() + 0xB77 bytes(s)
x01C994D1 (0x04E91C50 0x04F09080 0x04F03BD0 0x04AB91F4), addInstantiatedParametersToScope() + 0x131 bytes(s), f:\clang-
runk\llvm\tools\clang\lib\sema\sematemplateinstantiatedecl.cpp, line 2822 + 0x2F byte(s)
x01C9A779 (0x00001FF6 0x04F09080 0x00000000 0x00000000), clang::Sema::InstantiateFunctionDefinition() + 0x619 bytes(s),
f:\clang-trunk\llvm\tools\clang\lib\sema\sematemplateinstantiatedecl.cpp, line 3237 + 0x1F byte(s)
x01CEA8FE (0x04F09080 0x00001FF6 0x00000001 0x04ABA448), clang::Sema::DeduceReturnType() + 0x7E bytes(s), f:\clang-trun
\llvm\tools\clang\lib\sema\sematemplatededuction.cpp, line 4101
x01A8BB57 (0x04F09080 0x00001FF6 0x00000000 0xCCCCCCCC), clang::Sema::DiagnoseUseOfDecl() + 0x217 bytes(s), f:\clang-tr


 


http://llvm-reviews.chandlerc.com/D1784



More information about the cfe-commits mailing list