Skip to content

CWG2905 [temp.dep.constexpr] value-dependence of noexcept ( *expression* ) #554

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
MitalAshok opened this issue Jun 16, 2024 · 3 comments · Fixed by cplusplus/draft#7458
Closed

Comments

@MitalAshok
Copy link

Full name of submitter: Mital Ashok

Reference: [temp.dep.constexpr]

Issue description: Whether the operand of a noexcept operator is type-dependent is not enough to know if the noexcept operator is value-dependent. There are plenty of non-type-dependent expressions where whether or not it is potentially-throwing is dependent.

For example:

template<typename T>
void f() {
    noexcept(new int(T{}));
    noexcept(static_cast<int>(T{}));
    noexcept(typeid(*T{}));
    noexcept(delete T{});
}

GCC already treats all of these as value-dependent. Clang treats noexcept(new int(T{})) as a not value-dependent false but the rest of them as value-dependent.

Suggested resolution:

Remove noexcept from [temp.dep.constexpr]p2 so it becomes value-dependent if its operand is value-dependent according to [temp.dep.constexpr]p1

Expressions of the following form are value-dependent if the unary-expression or expression is type-dependent or the type-id is dependent:
sizeof unary-expression
[...]
noexcept ( expression )

@jensmaurer
Copy link
Member

CWG2905

@jensmaurer jensmaurer changed the title [temp.dep.constexpr] value-dependence of noexcept ( *expression* ) CWG2905 [temp.dep.constexpr] value-dependence of noexcept ( *expression* ) Jun 16, 2024
@MitalAshok
Copy link
Author

Actually this seems this is at odds with CWG1074.

Also value-dependence is only for constant expressions, which noexcept doesn't require (esp. since throwing an exception is not a constant expression)

Also some cases are missing from value-dependence still,

struct X {
    virtual void f();
};

template<typename T>
void g() {
    X value;
    noexcept(dynamic_cast<T&>(value));
}

(I think these are all caught by CWG2066 / CWG2109)

Perhaps noexcept should not rely on value-dependence at all and be:

noexcept ( expression ) is value-dependent if expression is an expression involving a template parameter

(See also: CWG1172, making this easier if "instantiation-dependent" was defined)

@jensmaurer
Copy link
Member

Yeah. Updated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants