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

avoid GCC -Wshadow warnings? #9

Closed
wojdyr opened this issue May 17, 2017 · 2 comments
Closed

avoid GCC -Wshadow warnings? #9

wojdyr opened this issue May 17, 2017 · 2 comments
Assignees

Comments

@wojdyr
Copy link

wojdyr commented May 17, 2017

At first glance it is only about constructors.
Would it be OK to change vec(T x, T y) : x(x), y(y) etc to, say, vec(T x_, T y_) : x(x_), y(y_)?

-Wshadow needs to be enabled explicitely so I guess few people use it. What's your opinion? I could provide PR if it'd be helpful.

../linalg.h: In constructor ‘constexpr linalg::vec<T, 2>::vec(T, T)’:
../linalg.h:69:69: warning: declaration of ‘y’ shadows a member of ‘linalg::vec<T, 2>’ [-Wshadow]
         constexpr                   vec(T x, T y)                   : x(x), y(y) {}
                                                                     ^
../linalg.h:67:39: note: shadowed declaration is here
         T                           x,y;
                                       ^
@sgorsten
Copy link
Owner

Thanks for bringing this to my attention. I've gone ahead and made this change.

In my own code, I make the deliberate choice to shadow member variables with constructor parameter names, both for brevity and for safety, as it prevents the (surprisingly legal in standard C++?!) mistake of copy-constructing a member variable from itself.

However, I understand that users may wish to compile with strict sets of warnings, and may possibly wish to do so in conjunction with -Werror. A minor stylistic quibble would be a silly reason to turn away users.

@wojdyr
Copy link
Author

wojdyr commented May 18, 2017

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants