Bug 70790 - Can't mangle noexcept expressions
Summary: Can't mangle noexcept expressions
Status: ASSIGNED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 10.0
: P3 normal
Target Milestone: ---
Assignee: Nathan Sidwell
URL:
Keywords: ABI, FIXME, rejects-valid
Depends on:
Blocks:
 
Reported: 2016-04-25 19:27 UTC by Eric Niebler
Modified: 2023-06-03 13:17 UTC (History)
4 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2020-04-08 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Eric Niebler 2016-04-25 19:27:17 UTC
#include <utility>

template<class T>
void foo(T, typename std::enable_if<noexcept(T(std::declval<T>())), int>::type)
{
}

int main() {
  foo(0,0);
}


Results in:

Test.cpp: In instantiation of ‘void foo(T, typename std::enable_if<noexcept ((T)(declval<T>())), int>::type) [with T = int; typename std::enable_if<noexcept ((T)(declval<T>())), int>::type = int]’:

Test.cpp:19:6: sorry, unimplemented: mangling noexcept_expr
 void foo(T, typename std::enable_if<noexcept(T(std::declval<T>())), int>::type)
      ^
Comment 1 Eric Niebler 2020-04-08 03:01:58 UTC
Still present on trunk, four years later.
Comment 2 Lewis Baker 2020-04-08 04:55:48 UTC
The relevant code seems to live in gcc/cp/mangle.c (at least for IA64 mangling)

Does it just need something like the following inserted into the write_expression() function?

```
  else if (TREE_CODE (expr) == NOEXCEPT_EXPR)
    {
      write_string ("nx");
      write_expression (TREE_OPERAND (expr, 0));
    }
```

The "nx" prefix seems to be what LLVM uses for its Itanium mangling.
See https://github.com/llvm/llvm-project/blob/13a1504ffb9a9a4f82dc1b60d9e8cbb173c7d030/clang/lib/AST/ItaniumMangle.cpp#L4057

Also see example showing this under clang (working) and gcc (failing): https://godbolt.org/z/yHrZDm
Comment 3 Nathan Sidwell 2020-04-08 16:45:59 UTC
... so I don't forget. but not a GCC 10 thing
Comment 4 GCC Commits 2023-06-03 13:17:48 UTC
The master branch has been updated by Patrick Palka <ppalka@gcc.gnu.org>:

https://gcc.gnu.org/g:999e617d3121b82921c8031ee695fd036f553f04

commit r14-1516-g999e617d3121b82921c8031ee695fd036f553f04
Author: Patrick Palka <ppalka@redhat.com>
Date:   Sat Jun 3 09:03:27 2023 -0400

    c++: mangle noexcept-expr [PR70790]
    
    This implements noexcept(expr) mangling and demangling as per the
    Itanium ABI.
    
            PR c++/70790
    
    gcc/cp/ChangeLog:
    
            * mangle.cc (write_expression): Handle NOEXCEPT_EXPR.
    
    libiberty/ChangeLog:
    
            * cp-demangle.c (cplus_demangle_operators): Add the noexcept
            operator.
            (d_print_comp_inner) <case DEMANGLE_COMPONENT_UNARY>: Always
            print parens around the operand of noexcept too.
            * testsuite/demangle-expected: Test noexcept operator
            demangling.
    
    gcc/testsuite/ChangeLog:
    
            * g++.dg/abi/mangle78.C: New test.