Patchwork C++ PATCH to fix constexpr/noexcept bug

login
register
mail settings
Submitter Jason Merrill
Date March 28, 2011, 3:49 p.m.
Message ID <4D90AE0C.6020402@redhat.com>
Download mbox | patch
Permalink /patch/88625/
State New
Headers show

Comments

Jason Merrill - March 28, 2011, 3:49 p.m.
We need to call cxx_constant_value after converting to bool, in case the 
conversion uses a conversion operator.

Tested x86_64-pc-linux-gnu, applying to trunk and 4.6.
commit a3fde3e7dcdc6b4f0b92bb273f4267c6bf8f6de0
Author: Jason Merrill <jason@redhat.com>
Date:   Sun Mar 27 21:51:35 2011 -0400

    	* except.c (build_noexcept_spec): Call cxx_constant_value after
    	converting to bool.

Patch

diff --git a/gcc/cp/except.c b/gcc/cp/except.c
index c05e507..a814d67 100644
--- a/gcc/cp/except.c
+++ b/gcc/cp/except.c
@@ -1203,10 +1203,10 @@  build_noexcept_spec (tree expr, int complain)
      it until instantiation.  */
   if (!processing_template_decl)
     {
-      expr = cxx_constant_value (expr);
       expr = perform_implicit_conversion_flags (boolean_type_node, expr,
 						complain,
 						LOOKUP_NORMAL);
+      expr = cxx_constant_value (expr);
     }
   if (expr == boolean_true_node)
     return noexcept_true_spec;
diff --git a/gcc/testsuite/g++.dg/cpp0x/constexpr-noexcept5.C b/gcc/testsuite/g++.dg/cpp0x/constexpr-noexcept5.C
new file mode 100644
index 0000000..7bf961b
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/constexpr-noexcept5.C
@@ -0,0 +1,15 @@ 
+// { dg-options -std=c++0x }
+
+struct booleable {
+  bool data;
+  constexpr explicit operator bool() { return data; }
+};
+
+constexpr booleable truthy_func() { return {true}; }
+
+void funky() noexcept(truthy_func()) {}
+
+int main() {
+  funky();
+  return 0;
+}