0

I've happily written C++ project in Visual Studio 2013. I did not use any non-standard extension explicitly, though when I moved to GCC 4.8 in Ubuntu I've received many errors, because I used non-standard extensions implicitly. For example:

#include <vector>

template<class T>
class A
{
    public:
    using MyVector = std::vector<T>;
};

template<class T>
class B : public A<T>
{
    MyVector vec;
};

This code(here is link) is legal with default settings of VS2013, though in GCC: error: 'MyVector' has not been defined, and it is conformant with ISO.

So my question is: if I'm 100% sure, that my code should be ISO-conformant, can I force visual studio to follow ISO C++ standard strictly?

DoctorMoisha
  • 1,613
  • 14
  • 25
  • Did you compile with `-std=c++11`? – NathanOliver Oct 06 '15 at 12:37
  • Yes, of course. I assume, that if I compiled without c++11, I've received different error about bad syntax. – DoctorMoisha Oct 06 '15 at 12:40
  • `1>source.cpp(9): error C2143: syntax error: missing ';' before 'template' 1>source.cpp(14): error C2143: syntax error: missing ';' before 'end of file'` – Simon Kraemer Oct 06 '15 at 12:48
  • 1
    Apart from the fact you are missing a ';' at the end of both class declarations, shouldn't the 'MyVector' declaration be hidden to derived classes because of the implicit private scope? – Sebacote Oct 06 '15 at 12:50
  • 1
    Did you try to compile with options [`/Za` and `/Zc`](https://msdn.microsoft.com/en-us/library/fwkeyyhe.aspx)? – nwp Oct 06 '15 at 12:54
  • @SébastienCôté No. It does work as stated above for MSVC and also works with gcc when using `typename A::MyVector vec;`. Look at the accepted answer here: http://stackoverflow.com/questions/1643035/propagating-typedef-from-based-to-derived-class-for-template – Simon Kraemer Oct 06 '15 at 12:54
  • @SimonKraemer Yes, it works because explicit lookup is not performed in gcc according to standard, though performed in VS. – DoctorMoisha Oct 06 '15 at 12:59
  • @SébastienCôté Oh, thank you, I've edited question – DoctorMoisha Oct 06 '15 at 13:00
  • @nwp `/Za` seems to do the trick: `main.cpp(13): error C3646: 'vec': unknown override specifier main.cpp(14): note: see reference to class template instantiation 'B' being compiled main.cpp(13): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int` – Simon Kraemer Oct 06 '15 at 13:00
  • @DoctorMoisha I was referring to the "implicit private scope" Sébastien mentioned – Simon Kraemer Oct 06 '15 at 13:00
  • 1
    You can use Clang as a compiler in MSVS now. – Kerrek SB Oct 06 '15 at 13:04
  • 1
    There are different problems with using `/Za`, like [Windows system headers not compiling](http://stackoverflow.com/questions/5489326/za-compiler-directive-does-not-compile-system-headers-in-vs2010). – Bo Persson Oct 06 '15 at 13:48
  • I’m voting to close this question because it's about old visual studio feature – DoctorMoisha Aug 09 '22 at 18:27

1 Answers1

0

There seems to be work undergoing in this direction by MS recently:

https://blogs.msdn.microsoft.com/vcblog/2016/11/16/permissive-switch/

You can try it, maybe it will solve problem at least partially.

Alex P
  • 23
  • 3