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

Fix -Wshadow clang warnings #13

Closed
wants to merge 1 commit into from

Conversation

jschueller
Copy link

@jschueller jschueller commented Mar 7, 2018

This fixes some annoying warnings with clang:

/home/schueller/projects/openturns/schueller3/lib/src/Base/Func/openturns/exprtk.hpp:16411:71: warning: declaration shadows a local variable [-Wshadow]
               static inline std::pair<bool,variable_node_t*> make(T& t,const bool is_const = false)
                                                                      ^
/home/schueller/projects/openturns/schueller3/lib/src/Base/Func/openturns/exprtk.hpp:16407:67: note: previous declaration is here
         inline bool add(const std::string& symbol_name, RawType& t, const bool is_const = false)
                                                                  ^
/home/schueller/projects/openturns/schueller3/lib/src/Base/Func/openturns/exprtk.hpp:16411:84: warning: declaration shadows a local variable [-Wshadow]
               static inline std::pair<bool,variable_node_t*> make(T& t,const bool is_const = false)
                                                                                   ^
/home/schueller/projects/openturns/schueller3/lib/src/Base/Func/openturns/exprtk.hpp:16407:81: note: previous declaration is here
         inline bool add(const std::string& symbol_name, RawType& t, const bool is_const = false)
                                                                                ^
/home/schueller/projects/openturns/schueller3/lib/src/Base/Func/openturns/exprtk.hpp:16417:82: warning: declaration shadows a local variable [-Wshadow]
               static inline std::pair<bool,stringvar_node_t*> make(std::string& t,const bool is_const = false)
                                                                                 ^
/home/schueller/projects/openturns/schueller3/lib/src/Base/Func/openturns/exprtk.hpp:16407:67: note: previous declaration is here
         inline bool add(const std::string& symbol_name, RawType& t, const bool is_const = false)
                                                                  ^
/home/schueller/projects/openturns/schueller3/lib/src/Base/Func/openturns/exprtk.hpp:16417:95: warning: declaration shadows a local variable [-Wshadow]
               static inline std::pair<bool,stringvar_node_t*> make(std::string& t,const bool is_const = false)
                                                                                              ^
/home/schueller/projects/openturns/schueller3/lib/src/Base/Func/openturns/exprtk.hpp:16407:81: note: previous declaration is here
         inline bool add(const std::string& symbol_name, RawType& t, const bool is_const = false)
                                                                                ^
/home/schueller/projects/openturns/schueller3/lib/src/Base/Func/openturns/exprtk.hpp:16423:75: warning: declaration shadows a local variable [-Wshadow]
               static inline std::pair<bool,function_t*> make(function_t& t, const bool is_constant = false)
                                                                          ^
/home/schueller/projects/openturns/schueller3/lib/src/Base/Func/openturns/exprtk.hpp:16407:67: note: previous declaration is here
         inline bool add(const std::string& symbol_name, RawType& t, const bool is_const = false)
                                                                  ^
/home/schueller/projects/openturns/schueller3/lib/src/Base/Func/openturns/exprtk.hpp:16428:89: warning: declaration shadows a local variable [-Wshadow]
               static inline std::pair<bool,vararg_function_t*> make(vararg_function_t& t, const bool is_const = false)
                                                                                        ^
/home/schueller/projects/openturns/schueller3/lib/src/Base/Func/openturns/exprtk.hpp:16407:67: note: previous declaration is here
         inline bool add(const std::string& symbol_name, RawType& t, const bool is_const = false)
                                                                  ^
/home/schueller/projects/openturns/schueller3/lib/src/Base/Func/openturns/exprtk.hpp:16428:103: warning: declaration shadows a local variable [-Wshadow]
               static inline std::pair<bool,vararg_function_t*> make(vararg_function_t& t, const bool is_const = false)
                                                                                                      ^
/home/schueller/projects/openturns/schueller3/lib/src/Base/Func/openturns/exprtk.hpp:16407:81: note: previous declaration is here
         inline bool add(const std::string& symbol_name, RawType& t, const bool is_const = false)
                                                                                ^
/home/schueller/projects/openturns/schueller3/lib/src/Base/Func/openturns/exprtk.hpp:16433:91: warning: declaration shadows a local variable [-Wshadow]
               static inline std::pair<bool,generic_function_t*> make(generic_function_t& t, const bool is_constant = false)
                                                                                          ^
/home/schueller/projects/openturns/schueller3/lib/src/Base/Func/openturns/exprtk.hpp:16407:67: note: previous declaration is here
         inline bool add(const std::string& symbol_name, RawType& t, const bool is_const = false)
                                                                  ^
/home/schueller/projects/openturns/schueller3/lib/src/Base/Func/openturns/exprtk.hpp:23280:55: warning: declaration shadows a local variable [-Wshadow]
                                          std::size_t s, std::size_t e,
                                                      ^
/home/schueller/projects/openturns/schueller3/lib/src/Base/Func/openturns/exprtk.hpp:23267:40: note: previous declaration is here
         void split(const std::string& s)
                                       ^
/home/schueller/projects/openturns/schueller3/lib/src/Base/Func/openturns/exprtk.hpp:36299:37: warning: declaration shadows a local variable [-Wshadow]
         static inline T process(T& x, T& y, expression<T>& expression)
                                    ^
/home/schueller/projects/openturns/schueller3/lib/src/Base/Func/openturns/exprtk.hpp:36251:10: note: previous declaration is here
      T  x = T(0);
         ^
/home/schueller/projects/openturns/schueller3/lib/src/Base/Func/openturns/exprtk.hpp:36299:43: warning: declaration shadows a local variable [-Wshadow]
         static inline T process(T& x, T& y, expression<T>& expression)
                                          ^
/home/schueller/projects/openturns/schueller3/lib/src/Base/Func/openturns/exprtk.hpp:36252:10: note: previous declaration is here
      T  y = T(0);

@jschueller jschueller changed the title Fix -Wshadow warnings Fix -Wshadow clang warnings Mar 7, 2018
@ArashPartow
Copy link
Owner

@jschueller Thanks for the PR. I have just tried building exprtk_test with fshadow and I'm not able reproduce those diagnostics.


Here is the clang++ output:

~/workspace/exprtk $ make clean exprtk_test
rm -f core.* *~ *.o *.bak *stackdump gmon.out *.gcda *.gcno *.gcnor *.gch
clang++ -pedantic-errors -Wall -Wextra -Werror -Wno-long-long -Wshadow -std=c++17 -O3 -march=native -o exprtk_test exprtk_test.cpp -L/usr/lib -lstdc++ -lm

~/workspace/exprtk $ clang++ --version
clang version 7.0.0 (trunk 326672)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /usr/local/bin

Here is the g++ output:

~/workspace/exprtk $ make clean exprtk_test
rm -f core.* *~ *.o *.bak *stackdump gmon.out *.gcda *.gcno *.gcnor *.gch
g++-7 -pedantic-errors -Wall -Wextra -Werror -Wno-long-long -Wshadow -std=c++17 -O3 -march=native -o exprtk_test exprtk_test.cpp -L/usr/lib -lstdc++ -lm

~/workspace/exprtk $ g++-7 --version
g++-7 (Ubuntu 7.2.0-1ubuntu1~16.04) 7.2.0
Copyright (C) 2017 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.

@jschueller
Copy link
Author

Mine is 3.8.0 from ubuntu 16.04:

/usr/bin/clang++ --version
clang version 3.8.0-2ubuntu4 (tags/RELEASE_380/final)
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin

@ArashPartow
Copy link
Owner

The shadow compiler option is very "noisy" when it comes to diagnostics. Have a look at the following talk to get a better idea:

https://www.youtube.com/watch?v=lkgszkPnV8g&f=&t=2377

Since Clang 4, the shadow option has been greatly improved with regards to SNR of its diagnostics. If possible give it a go.

I use the following script to checkout and build the latest version of clang:

https://gist.github.com/anonymous/51ea5545f534b49aaeadce69c3bfbc28

@ArashPartow ArashPartow closed this Mar 8, 2018
@jschueller
Copy link
Author

ok

@jschueller jschueller deleted the wshadow branch March 8, 2018 08:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants