Skip to content
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

Bad example in [expr.const]p7 #1627

Closed
zygoloid opened this issue May 11, 2017 · 1 comment
Closed

Bad example in [expr.const]p7 #1627

zygoloid opened this issue May 11, 2017 · 1 comment

Comments

@zygoloid
Copy link
Member

[expr.const]p7 says:

"""
If an expression of literal class type is used in a context where an integral constant expression is required, then that expression is contextually implicitly converted (Clause 7) to an integral or unscoped enumeration type and the selected conversion function shall be constexpr. [ Example:

struct A {
  constexpr A(int i) : val(i) { }
  constexpr operator int() const { return val; }
  constexpr operator long() const { return 43; }
private:
  int val;
};
template<int> struct X { };
constexpr A a = 42;
X<a> x;     // OK: unique conversion to int
int ary[a];   // error: ambiguous conversion

— end example ]
"""

This example appears to be unrelated to the rule in question.

In X<a>, a is implicitly converted to int, and the rule does not apply.
In int ary[a], a is implicitly converted to size_t, and the rule does not apply.

Neither case is a context in which an integral constant expression is required; those are alignas(E) and bit-widths for bit-fields (and now also the implicit std::tuple_size<T>::value in structured bindings). We should probably use one of those in this example instead.

@jensmaurer
Copy link
Member

jensmaurer commented Jul 15, 2017

"If an expression of literal class type is used in a context where an integral constant expression is required," only applies to bit-field widths and alignas anyway, so restrict appropriately (not in this editorial issue)

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

No branches or pull requests

2 participants