Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Did Visual Studio 2015 Update 3 Break Constructor Attributes?

In VS2015u2 the following code compiled fine.

class Foo {
public:
   [[deprecated]] Foo(std::string);
   Foo();
};

Under VS2015u3, I am getting an error:

C2416: attribute 'deprecated' cannot be applied in this context

This works in GCC 5.2 and it worked in earlier versions of VS2015. Granted, the deprecated attribute did not actually trigger a warning in VS2015, but that was not a significant concern.

Am I misunderstanding how to apply attributes to constructors? Or is VS2015u3 broken in this regard?

like image 538
Colorado.Rob Avatar asked Jul 14 '16 15:07

Colorado.Rob


People also ask

What is new in Visual Studio 2015 update 3?

Microsoft announced the new release of Visual Studio 2015 Update 3 on June 27 2016. The Visual Studio team addressed the known issues and reported issues, which are fixed on this release as well as an improved performance and stability of the product. What’s new in Visual Studio 2015 Update 3?

Is the constructor and destructor called in Visual Studio 2015?

But in Visual Studio 2015, the constructor and destructor aren't called. The compiler gives a warning about this behavior change. warning C4587: 'U::s': behavior change: constructor is no longer implicitly calledwarning C4588: 'U::s': behavior change: destructor is no longer implicitly called

Why does Visual Studio 2015 reject my C++ code?

This behavior is due to a regression in Visual Studio 2015 and Visual Studio 2015 Update 1; Visual Studio 2013 and previous versions of the compiler reject code written in this way. The behavior of Visual Studio 2015 and Visual Studio 2015 Update 1 is incorrect and doesn't conform to the C++ standard.

Does Visual Studio 2015 support C++ c2511?

The behavior of Visual Studio 2015 and Visual Studio 2015 Update 1 is incorrect and doesn't conform to the C++ standard. Visual Studio 2015 Update 2 rejects code written in this way and issues compiler error C2511 instead.


1 Answers

To put it shortly: Yes.

This is a bug wherein deprecated is allowed to be applied to the definition, but not to the declaration, of a constructor (other member functions seem fine). E.g. the following compiles cleanly, and unlike with Update 2, behaves correctly (yielding a C4996 diagnostic):

class Foo {
public:
    [[deprecated]] Foo(std::string) { }
    Foo() { }
};

Please submit a bug report to MS Connect and post back here with a link so that we may upvote it. :-]

like image 71
ildjarn Avatar answered Oct 17 '22 01:10

ildjarn