--
---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposal...@isocpp.org.
To post to this group, send email to std-pr...@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.
It sounds to me like you're saying that moving x from one part of the address space to another would constitute a breaking change. Are you really making that claim?
To put it another way, what in the current standard prevents that code from printing this?
0x400714
0x400714
0x400714
And under this proposed change, what would prevent that code from printing this?
0x7fff125fdad8
0x7fff125fdaa8
0x7fff125fda78
It sounds to me like you're saying that moving x from one part of the address space to another would constitute a breaking change. Are you really making that claim?
To put it another way, what in the current standard prevents that code from printing this?
0x400714
0x400714
0x400714
And under this proposed change, what would prevent that code from printing this?
0x7fff125fdad8
0x7fff125fdaa8
0x7fff125fda78
Ah, I hadn't noticed the addresses were varying in the static example. I grant that this could theoretically be a breaking change, but how much real code would be broken? The kinds of things you'd have to do to notice the difference seem like things that you'd normally never do with a constexpr variable.
Em dom 30 mar 2014, às 22:18:43, Geoffrey Romer escreveu:
> Ah, I hadn't noticed the addresses were varying in the static example. II'd say that for anyone who caused the address to be taken, they really want
> grant that this could theoretically be a breaking change, but how much real
> code would be broken? The kinds of things you'd have to do to notice the
> difference seem like things that you'd normally never do with a constexpr
> variable.
the current behaviour. So it will break a lot of code.
What's the benefit you were looking for?
The rules for odr-used in lambda are rather complicated, for a start: we've got const, static const.In general , it is recommended to write static constexpr anyway: why write two words instead of one?Another point is that it is constant, no matter how you look at it, why should it be automatic?I haven't written a proposal yet, but I meant all the contexts of defining constexpr variables:top-level, member and local.
On Monday, March 31, 2014 7:27:34 AM UTC+1, Thiago Macieira wrote:Em dom 30 mar 2014, às 22:18:43, Geoffrey Romer escreveu:
> Ah, I hadn't noticed the addresses were varying in the static example. I
> grant that this could theoretically be a breaking change, but how much real
> code would be broken? The kinds of things you'd have to do to notice the
> difference seem like things that you'd normally never do with a constexpr
> variable.
I'd say that for anyone who caused the address to be taken, they really want
the current behaviour. So it will break a lot of code.
What's the benefit you were looking for?
--
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
Software Architect - Intel Open Source Technology Center
PGP/GPG: 0x6EF45358; fingerprint:
E067 918B B660 DBD1 105C 966C 33F5 F005 6EF4 5358
--
---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposal...@isocpp.org.
To post to this group, send email to std-pr...@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.
For member variables, 'constexpr' implying 'static' would eliminate a possible evolution route for the language (constexpr non-static data members, whatever that might mean). The win here seems marginal, and it would make code more difficult to read, because it would no longer be obvious which members of a class are static. (thread_local implying static is already pretty bad in this regard.) I'm not sure you'll find consensus for a change here.
For local variables (declared 'constexpr' and not 'extern'), there are several compelling advantages. This case seems easiest to argue, and there's even implementation experience -- Clang's default compilation mode treats large, local, constant-enough variables as if they were static. (Here, "constant enough" means basically: a const-qualified type, a constant-foldable initializer, a trivial destructor, and no mutable members.) To my knowledge, only contrived test cases have ever had problems with this behavior.
Ah, I hadn't noticed the addresses were varying in the static example. I grant that this could theoretically be a breaking change, but how much real code would be broken? The kinds of things you'd have to do to notice the difference seem like things that you'd normally never do with a constexpr variable.
A constexpr variable must have static storage at some point, it's baked in when the program is compiled. Allowing it to be treated as non-static creates a weird set of corner cases.
I see three issues here:(1) Is there a strong case for mutable fields in a constexpr object?
(2) The advantage of having constexpr variables in a static segment is:(a) in a lambda expression, you don't have to capture them because they are static (automatically), no matter on which level they are defined;(b) if they are used as class members, you don't have to write special assignment operators for class objects;
(despite what some of you think, both these issues make it easier to use them by novices; as I mentioned before "odr-used" definition is too complicated; missing the word static leads to unexpected results; the language looks cleaner if static is implied);(3) There is an issue is with the other semantics of the word "static" (this word, on its own, is confusing enough): should constexpr variables be hidden from external usage? (I actually did not argue this case, but maybe it should be considered as well).
What do you think is wrong with 'extern constexpr'? It seems practically useful and consistent with the other language rules…
I don't follow this. If they're class members, they're already required to be static.
(despite what some of you think, both these issues make it easier to use them by novices; as I mentioned before "odr-used" definition is too complicated; missing the word static leads to unexpected results; the language looks cleaner if static is implied);(3) There is an issue is with the other semantics of the word "static" (this word, on its own, is confusing enough): should constexpr variables be hidden from external usage? (I actually did not argue this case, but maybe it should be considered as well).They already are (except in the corner case of a constexpr reference), because const type implies internal linkage.
>I don't follow this. If they're class members, they're already required to be static.I only meant "members in a class", which may belong to the class or an object of this class:
struct A{constexpr int x = 5;int y;};
vsstruct A1{static constexpr int x = 5;int y;};You have to write a special assignment for A, but not for A1.________________________________________________________________As for lambda:#include <iostream>const int& f(int a, const int& x) { return x;}int f(char a, int x) { return x;}int main(){constexpr int x = 17; // it will be OK if static is used here!auto g = [](auto a){const int i = f(a,x);std::cout << "i:" << i << std::endl;};g('a'); // okay: does not capture xg(17); // error: captures , but ok with static};
_____________________________________________________________>They already are (except in the corner case of a constexpr reference), because const type implies internal linkage.Yes, they are. I mentioned that I did not consider this case in my initial message.Show trimmed content
Actually, I hadn't formulated my first question correctly: