]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR c++/52026 (Constexpr Variable Appears Uninitialized in Lambda)
authorJason Merrill <jason@redhat.com>
Fri, 15 Feb 2013 18:32:12 +0000 (13:32 -0500)
committerJason Merrill <jason@gcc.gnu.org>
Fri, 15 Feb 2013 18:32:12 +0000 (13:32 -0500)
PR c++/52026
* semantics.c (finish_id_expression): In a template, return
the identifier for a constant variable.

From-SVN: r196087

gcc/cp/ChangeLog
gcc/cp/semantics.c
gcc/testsuite/g++.dg/cpp0x/lambda/lambda-const2.C [new file with mode: 0644]

index 794cc153d03f8cb80939a485d83d5ddaa3ce5744..78bf5647e657b278c9de8beba1a9cc785d4cf3f1 100644 (file)
@@ -1,5 +1,9 @@
 2013-02-15  Jason Merrill  <jason@redhat.com>
 
+       PR c++/52026
+       * semantics.c (finish_id_expression): In a template, return
+       the identifier for a constant variable.
+
        PR c++/55710
        * semantics.c (maybe_add_lambda_conv_op): Mark static thunk
        TREE_USED.
index 13ea6a5c97634e108b4e07c9c97567fa5a60ec35..cdc51902cd5979f372a4dda7a35aa9c830a68608 100644 (file)
@@ -2961,7 +2961,14 @@ finish_id_expression (tree id_expression,
 
             FIXME update for final resolution of core issue 696.  */
          if (decl_constant_var_p (decl))
-           return integral_constant_value (decl);
+           {
+             if (processing_template_decl)
+               /* In a template, the constant value may not be in a usable
+                  form, so look it up again at instantiation time.  */
+               return id_expression;
+             else
+               return integral_constant_value (decl);
+           }
 
          /* If we are in a lambda function, we can move out until we hit
             1. the context,
diff --git a/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-const2.C b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-const2.C
new file mode 100644 (file)
index 0000000..d2457d6
--- /dev/null
@@ -0,0 +1,15 @@
+// PR c++/52026
+// { dg-options "-std=c++11 -O" }
+// { dg-do run }
+
+template<bool B>
+int func() {
+  const int constVal1 = B ? 100 : -100;
+  const int constVal = constVal1;
+  return [] { return constVal; }();
+}
+
+int main() {
+  if (func<true>() != 100)
+    __builtin_abort ();
+}