--
--
Chromium Developers mailing list: chromi...@chromium.org
View archives, change email options, or unsubscribe:
http://groups.google.com/a/chromium.org/group/chromium-dev
---
You received this message because you are subscribed to the Google Groups "Chromium-dev" group.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/chromium-dev/CAMGbLiELMmHUV%2BorWB6o%2B1zbQeN5w%2BPTn-VxaaPKRZrZCtdMKw%40mail.gmail.com.
--
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/chromium-dev/CAMGbLiFA7%2B3LsVCbnEAiFrU%3Du1bLRaRgXvzyDy098BUTPpG8-A%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/chromium-dev/CAH%3DT95RvHOrY6asWiHbQ9Cmz%2BBt%2BFPxtuRvSBQuZjN97R2VgBw%40mail.gmail.com.
My $0.02: if char[] is actually being used for std::string operations, constexpr isn't helpful anyway since std::string doesn't have a constexpr constructor.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/chromium-dev/CADMqhVRQjWOJXVTcuUrLvMQRbc7hfOOZ0jW1Nhoxw5W8ZfNdbQ%40mail.gmail.com.
On 22 June 2018 at 10:10, Brandon Tolsch <bto...@chromium.org> wrote:My $0.02: if char[] is actually being used for std::string operations, constexpr isn't helpful anyway since std::string doesn't have a constexpr constructor.base::StringPiece has them though :)We could even add a templatizedtemplate <int STRLEN_PLUS_ONE>constexpr BasicStringPiece(const value_type (&string_literal)[N]) : ptr_(string_literal), length_(STRLEN_PLUS_ONE - 1) {}which would work with constexpr char kAboutBlankURL[] = "about:blank"; - but only those in a header file.... (#minor-advantage)(or, in fact, comments in string_piece.h suggest STRING_TYPE::traits_type::length() is constexpr in C++17, so maybe we don't even need that template)Concretely, this would avoid calls to strlen being done, e.g., by base::CommandLine::HasSwitch(..) during Chrome startup.
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-dev...@chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/chromium-dev/CAAGrfxdHD2Z9mA%3D4NYw9fMw_SutgSANPyyS%2Bu%2BPa%3Dbz50%3DxzOA%40mail.gmail.com.
"int constants in headers, string constants out of line" is what I thought we had been doing since chrome existed.
On Fri, Jun 22, 2018 at 1:35 PM Nico Weber <tha...@chromium.org> wrote:Do we have a rule like this?Yes, in the Google style guide; see the first sentence of http://google.github.io/styleguide/cppguide.html#Use_of_constexpr ."int constants in headers, string constants out of line" is what I thought we had been doing since chrome existed.
I'm not aware of that being a consistent common practice. "Random stuff in headers or .cc files or functions within .cc files" is all I can detect :)
I'm still curious whether, in a world where we had C++17 inline variables, your concerns would be addressed, or if there are still problems even then.
On Fri, Jun 22, 2018 at 4:41 PM Peter Kasting <pkas...@chromium.org> wrote:I'm not aware of that being a consistent common practice. "Random stuff in headers or .cc files or functions within .cc files" is all I can detect :)constexpr char kFoo[] in headers has 53 hits:extern const char kFoo[] has 1082:
I'm still curious whether, in a world where we had C++17 inline variables, your concerns would be addressed, or if there are still problems even then.I'd be happy with that. (It still means that the compiler does a bunch of work that the linker needs to undo, but it's small compared to, say, inline functions where the same thing already happens.)
--
--
Chromium Developers mailing list: chromi...@chromium.org
View archives, change email options, or unsubscribe:
http://groups.google.com/a/chromium.org/group/chromium-dev
---
You received this message because you are subscribed to the Google Groups "Chromium-dev" group.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/chromium-dev/CAAHOzFC2%2BpBbo%3D-0jg2Gz7H-hCQsdD0PxNe2U%3DOuHCrdUqqbMQ%40mail.gmail.com.
I want to define a string in a header file that I could process at compile-time using constexpr functions. There is not so many options, and defining a string as "constexpr char s[] = ..." is one of them. I cannot use extern with constexpr.There is another way which is to declare a string as a static constexpr field of a class. It's been discussed here: https://groups.google.com/a/chromium.org/forum/#!topic/chromium-dev/zu1NMS0RyrMWhich way should I prefer, given that this string will probably be not used at run-time at all?CL for context: https://crrev.com/c/1251361
--
--
Chromium Developers mailing list: chromi...@chromium.org
View archives, change email options, or unsubscribe:
http://groups.google.com/a/chromium.org/group/chromium-dev
---
You received this message because you are subscribed to the Google Groups "Chromium-dev" group.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/chromium-dev/CAKARY_mNihFTZgxgghJNusmKp9dzi18PQgeQNrkXAcQX-bRfwQ%40mail.gmail.com.
For Googlers, go/totw/140 has some discussion of this. Specifically:
// In foo.hconstexpr char kSpecial[] = "special";This creates one constant per translation unit that includes foo.h. It can result in &kSpecial having different values in different translation units. This is rare, but has apparently caused bugs. See link for details.
On Fri, Nov 9, 2018 at 4:38 PM James Cook <jame...@chromium.org> wrote:For Googlers, go/totw/140 has some discussion of this. Specifically:
// In foo.hconstexpr char kSpecial[] = "special";This creates one constant per translation unit that includes foo.h. It can result in &kSpecial having different values in different translation units. This is rare, but has apparently caused bugs. See link for details.It's worth noting that the context of this request are cases that
- Do not take the address of the constant
- Are "constexpr const char kFoo[]", not "constexpr char kFoo[]"; the two are meaningfully different and I can imagine the former being more amenable to not appearing in the binary
In that context, if it's actually true that there are no symbols produced for these constants, I'm fine with this. I'm not certain whether no symbols are produced. Seems like onus is on the author to demonstrate that. The claim is that the overall binary is 60kB smaller, which sounds like this is a win.PK
--
--
Chromium Developers mailing list: chromi...@chromium.org
View archives, change email options, or unsubscribe:
http://groups.google.com/a/chromium.org/group/chromium-dev
---
You received this message because you are subscribed to the Google Groups "Chromium-dev" group.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/chromium-dev/CAAHOzFBJ17HwmNYtp51qkKL5tfTKXXf%3Dk0FU5SM7uwkztVZtmQ%40mail.gmail.com.
On Sat, Nov 10, 2018 at 1:43 AM Peter Kasting <pkas...@chromium.org> wrote:On Fri, Nov 9, 2018 at 4:38 PM James Cook <jame...@chromium.org> wrote:For Googlers, go/totw/140 has some discussion of this. Specifically:
// In foo.hconstexpr char kSpecial[] = "special";This creates one constant per translation unit that includes foo.h. It can result in &kSpecial having different values in different translation units. This is rare, but has apparently caused bugs. See link for details.It's worth noting that the context of this request are cases that
- Do not take the address of the constant
- Are "constexpr const char kFoo[]", not "constexpr char kFoo[]"; the two are meaningfully different and I can imagine the former being more amenable to not appearing in the binary
I had thought that the second form ("constexpr char kFoo[] = "...";) meant "make kFoo a constant array holding the given terminated string and make it a compile-time constant." If this is true, it's the same as the first form ("constexpr const char kFoo[] = "...";), no? How are they different? Does the second form actually result in a char array that can be modified at runtime? Educate me! :-)
On Tue, Nov 13, 2018 at 3:05 AM Greg Thompson <g...@chromium.org> wrote:On Sat, Nov 10, 2018 at 1:43 AM Peter Kasting <pkas...@chromium.org> wrote:On Fri, Nov 9, 2018 at 4:38 PM James Cook <jame...@chromium.org> wrote:For Googlers, go/totw/140 has some discussion of this. Specifically:
// In foo.hconstexpr char kSpecial[] = "special";This creates one constant per translation unit that includes foo.h. It can result in &kSpecial having different values in different translation units. This is rare, but has apparently caused bugs. See link for details.It's worth noting that the context of this request are cases that
- Do not take the address of the constant
- Are "constexpr const char kFoo[]", not "constexpr char kFoo[]"; the two are meaningfully different and I can imagine the former being more amenable to not appearing in the binary
I had thought that the second form ("constexpr char kFoo[] = "...";) meant "make kFoo a constant array holding the given terminated string and make it a compile-time constant." If this is true, it's the same as the first form ("constexpr const char kFoo[] = "...";), no? How are they different? Does the second form actually result in a char array that can be modified at runtime? Educate me! :-)I think I'm confused. Arrays and pointers don't work the same here, and I was thinking of pointers.These two are meaningfully different:constexpr char* fooconstexpr const char* foo...because the "constexpr" makes the pointer const in both cases, rather than the data pointed to.*
But array types are not assignable, so "char foo[]" is more like "char* const foo" than "char* foo". So apparently the compiler parses "constexpr char foo[]" more like it parses "constexpr const char* const foo".
PK*For example, this compiles:char c = 'a';constexpr char* const p_c = &c;int main() {*p_c = 'b';return 0;}
--
--
Chromium Developers mailing list: chromi...@chromium.org
View archives, change email options, or unsubscribe:
http://groups.google.com/a/chromium.org/group/chromium-dev
---
You received this message because you are subscribed to the Google Groups "Chromium-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-dev...@chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/chromium-dev/CAAHOzFA7wqvRK0_6MLD4QbAL4%3DxQcWSFKMA8m5nqXSrwLtF_ZA%40mail.gmail.com.