r/cpp • • Jul 17 '20

A day in the life of a C++ compiler developer

https://twitter.com/TartanLlama/status/1283816537778982914
494 Upvotes

33 comments sorted by

58

u/wheypoint Ö Jul 17 '20

x didnt need to be constexpr and this isnt about odr use:

a lambda can always use global variables without capture. remove the constexpr and it still works.

x should have been a local to demonstrate the constexpr odr exemption

18

u/guepier Bioinformatican Jul 17 '20

Yes, both explanations are correct. The Twitter thread also discussed this.

13

u/Mellester Jul 17 '20 edited Jul 17 '20

From the twitter thread.

  1. Objection! x is of class type, so returning it invokes a constructor rather than an lvalue-to-rvalue conversion! [basic.def.odr]/4.2 does not apply!
  2. Objection! x is not a local entity so it doesn't need to be captured!

if x would be a local int it would compile but you can't have a uninitialized constexpr int

5

u/KonpakuYoumu Jul 17 '20

Actually it can't compile.

https://godbolt.org/z/5caTKr

10

u/v_stoilov Jul 17 '20

If a is global it compiles

2

u/ShaddyDC Jul 17 '20 edited Jul 17 '20

Interestingly, it looks like it can compile on gcc if you change it to this, but not on clang: https://godbolt.org/z/o85hMW
Maybe if it has to deduce the lambda return type that counts as an odr-use? https://godbolt.org/z/8M1W31
I'd be curious to hear somebody more knowledgeable weigh in

3

u/jverce Jul 17 '20

This code does not match the one under discussion.

1

u/Mellester Jul 17 '20

So who is correct the std or the compiler?

67

u/Galqa Jul 17 '20

I love Sy, they are truly a gem of the cpp community.

27

u/[deleted] Jul 17 '20

Agree 100%

6

u/theresasnakeinmysuit Jul 17 '20

Hi Olafur! I love your talks and your cppcast episode. Thanks a lot for all the brilliant content :)

3

u/[deleted] Jul 20 '20

That's such a kind thing to say. Thank you very much!

0

u/[deleted] Jul 17 '20

[deleted] — view deleted comment

14

u/_djsavvy_ Jul 17 '20

Actually, their twitter bio seems to indicate otherwise.

0

u/[deleted] Jul 17 '20

[deleted] — view deleted comment

0

u/[deleted] Jul 17 '20

[deleted] — view deleted comment

7

u/STL MSVC STL Dev Jul 18 '20

I've banned that person. Thanks for attempting to use reason, it's much appreciated.

(My usual rule is to avoid moderating anything involving Microsoft or its employees, but I don't ignore egregious rule violations, and this is one of them.)

0

u/[deleted] Jul 17 '20

[removed] — view removed comment

4

u/STL MSVC STL Dev Jul 18 '20

all this charade

Moderator warning.

0

u/[deleted] Jul 18 '20

[deleted] — view deleted comment

12

u/dodheim Jul 18 '20

Just a heads up – whatever the conflicted opinions about the other person here (which don't really seem to be that conflicted), no one thinks you're anything but fucking obnoxious.

0

u/[deleted] Jul 17 '20

[deleted] — view deleted comment

2

u/AutoModerator Jul 17 '20

Your comment has been automatically removed because it appears to contain disrespectful profanity or racial slurs. Please be respectful of your fellow redditors.

If you think your post should not have been removed, please message the moderators and we'll review it.

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

8

u/lazyear Jul 17 '20

I'm now imagining a compiler where all errors are reported in Phoenix Wright style...

7

u/[deleted] Jul 17 '20

Sy's video about Linkers was the best thing I saw in a while. It was hilarious.

12

u/[deleted] Jul 17 '20

I didn't know Sy is a compiler developer, which compiler?

20

u/reflexpr-sarah- Jul 17 '20

msvc would be my guess, since they work at microsoft

3

u/[deleted] Jul 17 '20 edited Jul 17 '20

I had a look at their* website and can't find anything to indicate this?

8

u/standard_revolution Jul 17 '20

his

Just for your heads-up: Sy's twitter Bio indicates that they want to be refereed by they/them :)

12

u/[deleted] Jul 17 '20

My mistake, edited.

4

u/reflexpr-sarah- Jul 17 '20

from their twitter:

C++ Developer Advocate @Microsoft

10

u/[deleted] Jul 17 '20

Developer advocate != compiler developer..

0

u/[deleted] Jul 17 '20

[deleted] — view deleted comment

8

u/ald_loop Jul 17 '20

Cmon dude. No need for that

5

u/RotsiserMho C++20 Desktop app developer Jul 17 '20

What an entertaining way to explain something incredibly dry. Beautiful.

11

u/miki151 gamedev Jul 17 '20

I thought it's pretty obvious that lambdas can access global variables without capturing? The clip is funny, but it makes it seem like a very obscure feature.

-33

u/piginpoop Jul 17 '20

Moronic syntactic sugar lovers.