This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

C++ PATCH to fix constexpr/noexcept bug


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.

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;
+}

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]