diff mbox

[c++] : Fix 61228 - noexcept(expression) causes internal compiler error

Message ID CAEwic4YAhWSbWS21=NGA8ymQB=UGU90VaexmeDgdZScsk_9xTA@mail.gmail.com
State New
Headers show

Commit Message

Kai Tietz Dec. 12, 2014, 7:45 p.m. UTC
Hi,

following patch fixes reported issue.
Tested for x86_64-w64-mingw32.  Ok for apply?

Regards,
Kai

ChangeLog

2014-12-12  Kai Tietz  <ktietz@redhat.com>

    PR c++/61228
    * call.c (set_flags_from_callee): Assume no throw
    by deferred noexcept.

2014-12-12  Kai Tietz  <ktietz@redhat.com>

    PR c++/61228
    * g++.dg/cpp0x/pr61228.C: New file.

ChangeLog testcase/g++.dg/cpp0x as pr61228.C:
// { dg-do run { target c++11 } }

#include <cctype>
#include <algorithm>

template<int (& F)(int)>
constexpr int safeCtype(unsigned char c) noexcept(noexcept(F(c)))
{ return F(c); }

int main()
{
  const char t[] = "a";
  std::find_if(t, t + 1, safeCtype<std::isspace>);
  return 0;
}

Comments

Paolo Carlini Dec. 12, 2014, 7:57 p.m. UTC | #1
Hi,

On 12/12/2014 08:45 PM, Kai Tietz wrote:
> #include <cctype>
> #include <algorithm>
I would recommend reducing the testcase further, <algorithm> is very large.

Thanks,
Paolo.
Jason Merrill Dec. 12, 2014, 8:15 p.m. UTC | #2
I think it would be better to call maybe_instantiate_noexcept so that we 
can have a definite answer.

Jason
Kai Tietz Dec. 12, 2014, 8:58 p.m. UTC | #3
2014-12-12 21:15 GMT+01:00 Jason Merrill <jason@redhat.com>:
> I think it would be better to call maybe_instantiate_noexcept so that we can
> have a definite answer.
>
> Jason

Hmm, for case that decl != NULL_TREE, this is ok.  But what if decl is
NULL_TREE?

Kai
Jason Merrill Dec. 13, 2014, 5:04 a.m. UTC | #4
On 12/12/2014 03:58 PM, Kai Tietz wrote:
> 2014-12-12 21:15 GMT+01:00 Jason Merrill <jason@redhat.com>:
>> I think it would be better to call maybe_instantiate_noexcept so that we can
>> have a definite answer.
>>
>> Jason
>
> Hmm, for case that decl != NULL_TREE, this is ok.  But what if decl is
> NULL_TREE?

We shouldn't have a deferred noexcept in that case.

Jason
diff mbox

Patch

Index: call.c
===================================================================
--- call.c      (Revision 218681)
+++ call.c      (Arbeitskopie)
@@ -335,11 +335,17 @@  set_flags_from_callee (tree call)
 {
   int nothrow;
   tree decl = get_callee_fndecl (call);
+  tree spec;

   /* We check both the decl and the type; a function may be known not to
      throw without being declared throw().  */
-  nothrow = ((decl && TREE_NOTHROW (decl))
-            || TYPE_NOTHROW_P (TREE_TYPE (TREE_TYPE (CALL_EXPR_FN (call)))));
+  nothrow = (decl && TREE_NOTHROW (decl));
+  if (!nothrow)
+    {
+      spec = TREE_TYPE (TREE_TYPE (CALL_EXPR_FN (call)));
+      nothrow = (!DEFERRED_NOEXCEPT_SPEC_P (TYPE_RAISES_EXCEPTIONS (spec))
+                 && TYPE_NOTHROW_P (spec));
+    }

   if (!nothrow && at_function_scope_p () && cfun && cp_function_chain)
     cp_function_chain->can_throw = 1;