<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - __attribute__((optnone)) not respected for included lambda"
   href="https://bugs.llvm.org/show_bug.cgi?id=41343">41343</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>__attribute__((optnone)) not respected for included lambda
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>clang
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>trunk
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Linux
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>normal
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>C++
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedclangbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>christian.weber@nokia.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>blitzrakete@gmail.com, dgregor@apple.com, erik.pilkington@gmail.com, llvm-bugs@lists.llvm.org, richard-llvm@metafoo.co.uk
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Test program test.cpp:

template <typename T>
class Test
{
    public:
    Test(){init();}

    template <typename U> 
    int doThis(){return 10;};

    template <typename U> 
    int doThat(){return 10;};

    private:
    void init() __attribute__((optnone));
};

template <typename T>
void Test<T>::init()
{
   [&](){this->template doThis<int>();}();
   this->template doThat<int>();
};


int main()
{
Test<bool> test;
}

clang -O3 test.cpp -c -o test.o
nm -C test.o
0000000000000000 T main
0000000000000000 W Test<bool>::init()
0000000000000000 W int Test<bool>::doThat<int>()
0000000000000000 W Test<bool>::init()::{lambda()#1}::operator()() const

I expect to see int Test<bool>::doThis<int>() in object file also.

Note: g++ 6.3.1a is not optimizing away the lambda function if
__attribute__((optnone))__ is replaced by __attribute__((optimize(0))) :

g++ -O3 test.cpp -c -o test_g++.o
nm -C test_g++.o
0000000000000000 T main
0000000000000000 W Test<bool>::init()
0000000000000000 t int Test<bool>::doThat<int>() [clone .isra.1]
0000000000000000 t int Test<bool>::doThis<int>() [clone .isra.0]
0000000000000000 W Test<bool>::init()::{lambda()#1}::operator()() const</pre>
        </div>
      </p>


      <hr>
      <span>You are receiving this mail because:</span>

      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>