Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gcc complains "pragma once" in *.cpp file #80

Closed
bigcat26 opened this issue Feb 25, 2021 · 15 comments · Fixed by #82
Closed

gcc complains "pragma once" in *.cpp file #80

bigcat26 opened this issue Feb 25, 2021 · 15 comments · Fixed by #82
Assignees
Labels
enhancement New feature or request released

Comments

@bigcat26
Copy link
Contributor

gcc version

c++ (Ubuntu 9.3.0-17ubuntu1~20.04) 9.3.0
Copyright (C) 2019 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

compiler output:

[  1%] Building CXX object CMakeFiles/casbin.dir/casbin/enforcer.cpp.o
/usr/bin/c++    -g   -std=gnu++11 -o CMakeFiles/casbin.dir/casbin/enforcer.cpp.o -c /home/bigcat26/work/lab/third_party/casbin/casbin/enforcer.cpp
/home/bigcat26/work/lab/third_party/casbin/casbin/enforcer.cpp:17:9: warning: #pragma once in main file
   17 | #pragma once
      |         ^~~~
[  3%] Building CXX object CMakeFiles/casbin.dir/casbin/enforcer_cached.cpp.o
/usr/bin/c++    -g   -std=gnu++11 -o CMakeFiles/casbin.dir/casbin/enforcer_cached.cpp.o -c /home/bigcat26/work/lab/third_party/casbin/casbin/enforcer_cached.cpp
/home/bigcat26/work/lab/third_party/casbin/casbin/enforcer_cached.cpp:17:9: warning: #pragma once in main file
   17 | #pragma once
      |         ^~~~
[  5%] Building CXX object CMakeFiles/casbin.dir/casbin/internal_api.cpp.o
/usr/bin/c++    -g   -std=gnu++11 -o CMakeFiles/casbin.dir/casbin/internal_api.cpp.o -c /home/bigcat26/work/lab/third_party/casbin/casbin/internal_api.cpp
/home/bigcat26/work/lab/third_party/casbin/casbin/internal_api.cpp:17:9: warning: #pragma once in main file
   17 | #pragma once
      |         ^~~~
[  7%] Building CXX object CMakeFiles/casbin.dir/casbin/management_api.cpp.o
/usr/bin/c++    -g   -std=gnu++11 -o CMakeFiles/casbin.dir/casbin/management_api.cpp.o -c /home/bigcat26/work/lab/third_party/casbin/casbin/management_api.cpp
/home/bigcat26/work/lab/third_party/casbin/casbin/management_api.cpp:17:9: warning: #pragma once in main file
   17 | #pragma once
      |         ^~~~
[  8%] Building CXX object CMakeFiles/casbin.dir/casbin/model/function.cpp.o
/usr/bin/c++    -g   -std=gnu++11 -o CMakeFiles/casbin.dir/casbin/model/function.cpp.o -c /home/bigcat26/work/lab/third_party/casbin/casbin/model/function.cpp
/home/bigcat26/work/lab/third_party/casbin/casbin/model/function.cpp:17:9: warning: #pragma once in main file
   17 | #pragma once
      |         ^~~~
[ 10%] Building CXX object CMakeFiles/casbin.dir/casbin/rbac_api.cpp.o
/usr/bin/c++    -g   -std=gnu++11 -o CMakeFiles/casbin.dir/casbin/rbac_api.cpp.o -c /home/bigcat26/work/lab/third_party/casbin/casbin/rbac_api.cpp
/home/bigcat26/work/lab/third_party/casbin/casbin/rbac_api.cpp:17:9: warning: #pragma once in main file
   17 | #pragma once
      |         ^~~~
[ 12%] Building CXX object CMakeFiles/casbin.dir/casbin/rbac_api_with_domains.cpp.o
/usr/bin/c++    -g   -std=gnu++11 -o CMakeFiles/casbin.dir/casbin/rbac_api_with_domains.cpp.o -c /home/bigcat26/work/lab/third_party/casbin/casbin/rbac_api_with_domains.cpp
/home/bigcat26/work/lab/third_party/casbin/casbin/rbac_api_with_domains.cpp:17:9: warning: #pragma once in main file
   17 | #pragma once
      |         ^~~~
[ 14%] Building CXX object CMakeFiles/casbin.dir/casbin/util/built_in_functions.cpp.o
/usr/bin/c++    -g   -std=gnu++11 -o CMakeFiles/casbin.dir/casbin/util/built_in_functions.cpp.o -c /home/bigcat26/work/lab/third_party/casbin/casbin/util/built_in_functions.cpp
/home/bigcat26/work/lab/third_party/casbin/casbin/util/built_in_functions.cpp:17:9: warning: #pragma once in main file
   17 | #pragma once
      |         ^~~~
@hsluoyz hsluoyz self-assigned this Feb 25, 2021
@hsluoyz hsluoyz added the bug Something isn't working label Feb 25, 2021
@hsluoyz hsluoyz moved this from Casbin Easy Tasks to Casbin-CPP Easy Tasks in Casbin Easy Tasks for Beginners/Student Applicants Feb 25, 2021
@hsluoyz
Copy link
Member

hsluoyz commented Feb 25, 2021

@bigcat26 can you make a PR to fix it?

@hsluoyz
Copy link
Member

hsluoyz commented Feb 25, 2021

@Zxilly

@Zxilly
Copy link

Zxilly commented Feb 25, 2021

got it, working on this

@bigcat26
Copy link
Contributor Author

find . -name '*.cpp' |xargs sed -i -z -e  "s/#pragma once\n\n//"
# commit & push

@Zxilly
Copy link

Zxilly commented Feb 25, 2021

@bigcat26 seems #pragma once was added deliberately
ref to: b69e3a3, 18b41bc and 52929cb
Warnings were explicitly ignored.
Maybe prepared for some magic usage?

@bigcat26
Copy link
Contributor Author

@bigcat26 seems #pragma once was added deliberately
ref to: b69e3a3, 18b41bc and 52929cb
Warnings were explicitly ignored.
Maybe prepared for some magic usage?

I love magic.
I just think replace '#ifdef/#define/#endif' with '#pragma once' in header files is reasonable..
Pragma_once

@Zxilly
Copy link

Zxilly commented Feb 25, 2021

@bigcat26 so just add #pragma once in *.h?
I think they can work together.

@divy9881
Copy link
Member

divy9881 commented Feb 25, 2021

MS VC++ requires #pragma once for its efficient execution on windows platform. We cannot do much about it. That's a trade-off we need to make while building the same code on linux. I have prepared 2 separate routines in Makefile script to build the library.

make

The above sets off the warnings. But, under development environment we do need warning logs. Under such cases, we build using

make debug

@divy9881 divy9881 added enhancement New feature or request and removed bug Something isn't working labels Feb 25, 2021
@hsluoyz
Copy link
Member

hsluoyz commented Feb 25, 2021

@divy9881 @bigcat26 can we wrap the #pragma once into a ifdef? Like:

#ifdef WINDOWS_MSVC
#pragma once
#endif

@bigcat26
Copy link
Contributor Author

  1. In my knowledge, pragma once is a compiler directive, it just work at compile time, it is replacement of header guard macro.
  2. MSVC compiler support "precompile header" help speed up compile progress.
  3. Is there any document describes how "pragma once" optimize msvc program runtime speed?

@Zxilly
Copy link

Zxilly commented Feb 25, 2021

@bigcat26 https://docs.microsoft.com/en-us/cpp/preprocessor/once?view=msvc-160

We recommend the #pragma once directive for new code because it doesn't pollute the global namespace with a preprocessor symbol. It requires less typing, it's less distracting, and it can't cause symbol collisions. Symbol collisions are errors caused when different header files use the same preprocessor symbol as the guard value. It isn't part of the C++ Standard, but it's implemented portably by several common compilers.

@bigcat26
Copy link
Contributor Author

bigcat26 commented Feb 25, 2021

@bigcat26 https://docs.microsoft.com/en-us/cpp/preprocessor/once?view=msvc-160

We recommend the #pragma once directive for new code because it doesn't pollute the global namespace with a preprocessor symbol. It requires less typing, it's less distracting, and it can't cause symbol collisions. Symbol collisions are errors caused when different header files use the same preprocessor symbol as the guard value. It isn't part of the C++ Standard, but it's implemented portably by several common compilers.

It has an effect similar to the include guard idiom, which uses preprocessor macro definitions to prevent multiple inclusions of the contents of the file.

@EmperorYP7
Copy link
Member

EmperorYP7 commented Mar 11, 2021

I don't think there is any noticeable compile time performance difference between #pagma once and include-guards on MSVC++ which is evident in this SO discussion. Include guards are more generic and won't throw warnings on compilation with Clang and GCC on MacOS and Linux (tested it myself). May I go ahead and create a PR for this?

@github-actions
Copy link

🎉 This issue has been resolved in version 1.11.6 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

@hsluoyz
Copy link
Member

hsluoyz commented Mar 11, 2021

Good work!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request released
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants