kastnermario / yaml-cpp

Automatically exported from code.google.com/p/yaml-cpp
MIT License
0 stars 0 forks source link

#pragma once protection too liberal #115

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. build with a non-gcc compiler that doesn't support "#pragma once"

What is the expected output? What do you see instead?

The check for gcc version that protects the use of "#pragma once" will not do 
the right thing in many cases.

Sun Studio doesn't support "#pragma once" and does not define __GNUC__ - the 
same is true for any compiler that isn't gcc, and doesn't support "#pragma 
once".

What version of the product are you using? On what operating system?

Sun Studio 12 on x86 Solaris

Please provide any additional information below.

Perhaps it would be cleaner to use a conditional that essentially looked for 
compilers that are known to support this extension.

#if defined(_MSC_VER) || ( defined(__GNUC__) && __GNUC__ == 3 && __GNUC_MINOR__ 
>= 4) || (__GNUC__ >= 4) // GCC supports "pragma once" correctly since 3.4
#pragma once
#endif

Although not every version of Visual studio would support #pragma once, I 
believe it's been there long enough that you won't have any users with 
compilers that old.

Original issue reported on code.google.com by rboe...@gmail.com on 22 Aug 2011 at 9:36

GoogleCodeExporter commented 8 years ago
What actually happens with the Sun compiler? Does it compile incorrectly? Does 
it list a bunch of warnings?

There's an include guard as well, so if it doesn't know what to do with "pragma 
once", it should just ignore it, and the include guard would take over, I think.

The reason the #if statement is there for gcc is that old versions of gcc gave 
a bunch of warnings about it: 
http://code.google.com/p/yaml-cpp/issues/detail?id=91

Original comment by jbe...@gmail.com on 22 Aug 2011 at 9:43

GoogleCodeExporter commented 8 years ago
The Sun compiler warns about "unknown pragma" which is pretty typical.
So, the reason to modify the macro that protects the pragma is the same as for 
gcc, and generally it's a good idea to only add a very helpful pragma when you 
have verified that it is supported.

I don't know of any compilers other than GCC and MS Visual C++ that have this, 
but I would guess there are some...  Poking around the web I don't see any C++ 
compilers other than these though.

IMHO, this is about as good as you can get, use pragma once where you *know* 
it's supported, and also have regular old include guards for systems where it's 
not.

Original comment by rboe...@gmail.com on 25 Aug 2011 at 5:38

GoogleCodeExporter commented 8 years ago
Fixed, r292:fa9911436ac6. Thanks!

Original comment by jbe...@gmail.com on 6 Sep 2011 at 5:16