<html>
    <head>
      <base href="http://llvm.org/bugs/" />
    </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 --- - this pointer isn't qualified within decltype() when used in member function declaration with late specified return type"
   href="http://llvm.org/bugs/show_bug.cgi?id=16243">16243</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>this pointer isn't qualified within decltype() when used in member function declaration with late specified return type
          </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>All
          </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++11
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>mitchnull+llvm@gmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>dgregor@apple.com, llvmbugs@cs.uiuc.edu
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Created <span class=""><a href="attachment.cgi?id=10636" name="attach_10636" title="test program showing the failure">attachment 10636</a> <a href="attachment.cgi?id=10636&action=edit" title="test program showing the failure">[details]</a></span>
test program showing the failure

The explicit 'this' pointer in member function declaration with late specified
return type using decltype is not const-qualified if the member function is
declared 'const' resulting in wrong return type.

Example:

template <typename T>
struct DecltypeConstThis {

    void f() {}
    T f() const { return T{}; }

    auto g() -> decltype(this->f()) { return f(); }
    auto g() const  ->  decltype(this->f()) { return f(); } // apparently
'this' is not const within the decltype() here

};

int main() {
    DecltypeConstThis<int> d;
    const DecltypeConstThis<int> &cd = d;

    d.g();
    cd.g(); // fails
    return 0;
}

compilation error:
[mitch@deneb src]$ clang++ -std=c++11 -o decltype-const-this
decltype-const-this.cpp
decltype-const-this.cpp:8:47: error: void function 'g' should not return a
value
      [-Wreturn-type]
    auto g() const  ->  decltype(this->f()) { return f(); } // apparently
'this' is...
                                              ^      ~~~
decltype-const-this.cpp:17:8: note: in instantiation of member function
      'DecltypeConstThis<int>::g' requested here
    cd.g(); // fails

The same code works as expected with implicit 'this':

template <typename T>
struct DecltypeConstThis {

    void f() {}
    T f() const { return T{}; }

    auto g() -> decltype(f()) { return f(); }
    auto g() const  ->  decltype(f()) { return f(); } //  decltype() correctly
picks 'f() const' here

};

int main() {
    DecltypeConstThis<int> d;
    const DecltypeConstThis<int> &cd = d;

    d.g();
    cd.g();
    return 0;
}

(ps: gcc-4.8 requires the explicit this-> here, filing a bug report that way,
too)</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>