<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 --- - constexpr function ill-formed but error message incorrect"
   href="http://llvm.org/bugs/show_bug.cgi?id=18874">18874</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>constexpr function ill-formed but error message incorrect
          </td>
        </tr>

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

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

        <tr>
          <th>Hardware</th>
          <td>Other
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>other
          </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++1y
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>yaghmour.shafik@gmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvmbugs@cs.uiuc.edu
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>In the following program:

#include <cstddef>

template <typename T, size_t s>
struct test
{  
     T x[s] ;
} ;

template <typename T>
constexpr T func() {
    test<T,3> test1 ;

  test1.x[0] = 10 ;
  return test1.x[0];
}

constexpr int func2() {
    test<int,3> test1 ;

  test1.x[0] = 10 ;
  return test1.x[0];
}


int main()
{
    constexpr int x = func<int>();
}

func and func2 should be ill-formed for the same reason that variable test1 is
not initialized nor does it have a constexpr constructor but in func the error
message is:

  main.cpp:13:11: note: assignment to object outside its lifetime is not
allowed in a constant expression
    test1.x[0] = 10 ;
               ^

which does not make any sense since test1 should be trivial and it's lifetime
should begin with it's declaration and extend over the whole function.

I would expect an error similar to the one we see for func2 which is as
follows:

  main.cpp:20:14: note: non-constexpr constructor 'test' cannot be used in a
constant expression
      test<int,3> test1 ;
                  ^

I am building using the following command line:

  clang++ -std=c++1y -O0 -Wall -Wextra -Wconversion -pedantic 

You can see this on Coliru here:

  <a href="http://coliru.stacked-crooked.com/a/16ed43ed478fbc55">http://coliru.stacked-crooked.com/a/16ed43ed478fbc55</a>

This was originally brought up in this StackOverflow question:

 
<a href="http://stackoverflow.com/questions/21806154/c1y-c14-assignment-to-object-outside-its-lifetime-is-not-allowed-in-a-const">http://stackoverflow.com/questions/21806154/c1y-c14-assignment-to-object-outside-its-lifetime-is-not-allowed-in-a-const</a>

This does not seem like a major bug but the error message sure is confusing.</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>