Live data from Hacker News

The weirdest bug I’ve found in a compiler: MSVC 2017

medium.com

1–10 of 61 posts

Re: The weirdest bug I’ve found in a compiler: MSVC 2017

#3

   template 
   using func_type = decltype(U{}.func());
I admit I'm not following all the new stuff that is added to C++. What are that two lines supposed to mean? I don't know what the U{}.func() and using x = decltype() constructs should mean or their names.

The names of these and links highly appreciated. Thanks.

Moreover, regarding the "bug": if "U" is actually special as an identifier (e.g. some predefined macro or something) it's a pity that the author hasn't investigated a little more. Even not knowing the meaning of the lines I've quoted, the symptoms look somewhat familiar to me with these "special behaviors" of identifiers.

Re: The weirdest bug I’ve found in a compiler: MSVC 2017

#4
post #3

template using func_type = decltype(U{}.func()); I admit I'm not following all the new stuff that is added to C++. What are that two lines supposed to mean? I don't know what the U{}.func() and using x = decltype() constructs should mean or their names. The names of these and links highly appreciated. Thanks. Moreover, regarding the "bug": if "U" is actually special as an identifier (e.g. some predefined macro or som…

Didn't you read the rest of the article? They tested with arguments with different names. Further they showed that T was accessible from within the other template when it didn't have a template parameter T, making this even more bizarre.

Also, just to be completely sure, I tested it myself.

Using X: https://godbolt.org/g/B9YEgZ

Showing the template parameter leaking with neither T nor U: https://godbolt.org/g/CKe2wG

Re: The weirdest bug I’ve found in a compiler: MSVC 2017

#5
I tried remember reading an article on HN a couple of years ago about how MSVC got initial C++ support and added more and more features over time, despite having not being designed with C++ in mind originally. The result was a combination of clever hacks after clever hacks, with the consequence being the reputation MSVC got over time (I'm not saying this is one the consequence shown in the OP)

Anyway, does anybody still have this article somewhere? I couldn't find it anymore :(

Re: The weirdest bug I’ve found in a compiler: MSVC 2017

#6
post #3

template using func_type = decltype(U{}.func()); I admit I'm not following all the new stuff that is added to C++. What are that two lines supposed to mean? I don't know what the U{}.func() and using x = decltype() constructs should mean or their names. The names of these and links highly appreciated. Thanks. Moreover, regarding the "bug": if "U" is actually special as an identifier (e.g. some predefined macro or som…

Here is a link that describes value initialization: http://en.cppreference.com/w/cpp/language/value_initializati... and aggregate initialization: http://en.cppreference.com/w/cpp/language/aggregate_initiali...

Either of which could apply to 'U{}'.

decltype is just returning the result type of the contained expression, which is the return type of the method 'func' called on a default or value initialized instance of type U. A lot of times people will use std::declval() instead which returns a reference to U w/o needing to call a valid constructor (https://en.cppreference.com/w/cpp/utility/declval).

The templated using statement is creating a template type 'func_type' which is similar to a typedef.

Re: The weirdest bug I’ve found in a compiler: MSVC 2017

#7
post #3

template using func_type = decltype(U{}.func()); I admit I'm not following all the new stuff that is added to C++. What are that two lines supposed to mean? I don't know what the U{}.func() and using x = decltype() constructs should mean or their names. The names of these and links highly appreciated. Thanks. Moreover, regarding the "bug": if "U" is actually special as an identifier (e.g. some predefined macro or som…

I can't guarantee I'm right, but AFAIK that's sort of a templated typedef, where the bound type is that of the return value of method "func" of class U. Short example:

  class Foo {
    int func();
  };

  // func_type = int
Also, for more info, see http://en.cppreference.com/w/cpp/language/type_alias, https://en.cppreference.com/w/cpp/language/decltype.

Re: The weirdest bug I’ve found in a compiler: MSVC 2017

#8
post #5

I tried remember reading an article on HN a couple of years ago about how MSVC got initial C++ support and added more and more features over time, despite having not being designed with C++ in mind originally. The result was a combination of clever hacks after clever hacks, with the consequence being the reputation MSVC got over time (I'm not saying this is one the consequence shown in the OP) Anyway, does anybody st…

MSVC has had C++ support for a long time, to be fair. GCC was probably just as bad at first, it just improved more steadily over time. Today, GCC and Clang both seem like very robust C++ compilers, and it doesn't feel like MSVC is terribly far behind (it does feels like it is behind, in my perception, just not far.)

Re: The weirdest bug I’ve found in a compiler: MSVC 2017

#9
I've crashed MSVC 15.7 repeatedly while writing templates - usually due to an error in my code, but sometimes on valid code. I really do appreciate that Microsoft has been developing their C++ compiler a lot faster than in the past, but this seems like a buggy release.

Re: The weirdest bug I’ve found in a compiler: MSVC 2017

#10
post #3

template using func_type = decltype(U{}.func()); I admit I'm not following all the new stuff that is added to C++. What are that two lines supposed to mean? I don't know what the U{}.func() and using x = decltype() constructs should mean or their names. The names of these and links highly appreciated. Thanks. Moreover, regarding the "bug": if "U" is actually special as an identifier (e.g. some predefined macro or som…

I can't guarantee I'm right, but AFAIK that's sort of a templated typedef, where the bound type is that of the return value of method "func" of class U. Short example: class Foo { int func(); }; // func_type = int Also, for more info, see http://en.cppreference.com/w/cpp/language/type_alias , https://en.cppreference.com/w/cpp/language/decltype .

Thanks, in type_alias document I see the example:

    template
    using Vec = vector>; // type-id is vector>
    Vec v; // Vec is the same as vector>
That explains to me the using construct.

And tcbawo's answer tries to address the U{}.func()

However "either of which could apply to U{}" ... I'd expect that it should be possible to say which of these is in this example? I also can't see how that can (or should?) match "aggregate_initialization."

Post reply on HN