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

shadowing error #73

Closed
lianyant opened this issue Mar 29, 2024 · 2 comments
Closed

shadowing error #73

lianyant opened this issue Mar 29, 2024 · 2 comments

Comments

@lianyant
Copy link

version: tag v0.1.3
use gnu9.3.0 cmake3.26.0 ubuntu18.04--x86_64
When I encountered this issue while compiling the project:

In file included from /home/lianyan/5050pp/libvda5050pp/build/deps/eventpp-src/include/eventpp/eventdispatcher.h:17,
from /home/lianyan/5050pp/libvda5050pp/build/deps/eventpp-src/include/eventpp/eventqueue.h:17,
from /home/lianyan/5050pp/libvda5050pp/src/../include/private/vda5050++/core/action_event_manager.h:11,
from /home/lianyan/5050pp/libvda5050pp/src/../include/private/vda5050++/core/instance.h:18,
from /home/lianyan/5050pp/libvda5050pp/src/vda5050++/config.cpp:16:
/home/lianyan/5050pp/libvda5050pp/build/deps/eventpp-src/include/eventpp/callbacklist.h: 在构造函数‘eventpp::internal::CallbackListBase<ReturnType(Args ...), PoliciesType>::Node::Node(const Callback
&, eventpp::internal
::CallbackListBase<ReturnType(Args ...), PoliciesType>::Node::Counter)’中:
/home/lianyan/5050pp/libvda5050pp/build/deps/eventpp-src/include/eventpp/callbacklist.h:64:4: 错误:declaration of ‘counter’ shadows a member of ‘eventpp::internal::CallbackListBase<ReturnType(Args ...), PoliciesType>::Node’ [-Werror=shadow]
64 | : callback(callback), counter(counter)
| ^
/home/lianyan/5050pp/libvda5050pp/build/deps/eventpp-src/include/eventpp/callbacklist.h:71:11: 附注:被隐藏的声明在这里
71 | Counter counter;
| ^~~~~~~
/home/lianyan/5050pp/libvda5050pp/build/deps/eventpp-src/include/eventpp/callbacklist.h:64:4: 错误:declaration of ‘callback’ shadows a member of ‘eventpp::internal::CallbackListBase<ReturnType(Args ...), PoliciesType>::Node’ [-Werror=shadow]
64 | : callback(callback), counter(counter)
| ^
/home/lianyan/5050pp/libvda5050pp/build/deps/eventpp-src/include/eventpp/callbacklist.h:70:13: 附注:被隐藏的声明在这里
70 | Callback
callback;
| ^~~~~~~~
In file included from /home/lianyan/5050pp/libvda5050pp/src/../include/private/vda5050++/core/action_event_manager.h:11,
from /home/lianyan/5050pp/libvda5050pp/src/../include/private/vda5050++/core/instance.h:18,
from /home/lianyan/5050pp/libvda5050pp/src/vda5050++/config.cpp:16:
/home/lianyan/5050pp/libvda5050pp/build/deps/eventpp-src/include/eventpp/eventqueue.h: 在构造函数‘eventpp::internal::EventQueueBase<EventType
, ReturnType(Args ...), Policies_>::DisableQueueNotify::DisableQueueNotify(eventpp::internal_::EventQueueBase<EventType_, ReturnType(Args ...), Policies_>*)’中:
/home/lianyan/5050pp/libvda5050pp/build/deps/eventpp-src/include/eventpp/eventqueue.h:104:4: 错误:declaration of ‘queue’ shadows a member of ‘eventpp::internal::EventQueueBase<EventType_, ReturnType(Args ...), Policies_>::DisableQueueNotify’ [-Werror=shadow]
104 | : queue(queue)
| ^
/home/lianyan/5050pp/libvda5050pp/build/_deps/eventpp-src/include/eventpp/eventqueue.h:118:20: 附注:被隐藏的声明在这里
118 | EventQueueBase * queue;
| ^~~~~
In file included from /home/lianyan/5050pp/libvda5050pp/src/../include/private/vda5050++/core/action_event_manager.h:12,
from /home/lianyan/5050pp/libvda5050pp/src/../include/private/vda5050++/core/instance.h:18,
from /home/lianyan/5050pp/libvda5050pp/src/vda5050++/config.cpp:16:
/home/lianyan/5050pp/libvda5050pp/build/_deps/eventpp-src/include/eventpp/utilities/scopedremover.h: 在构造函数‘eventpp::ScopedRemover<DispatcherType, typename std::enable_if<std::is_base_of<eventpp::TagEventDispatcher, DispatcherType>::value>::type>::ScopedRemover(DispatcherType&)’中:
/home/lianyan/5050pp/libvda5050pp/build/_deps/eventpp-src/include/eventpp/utilities/scopedremover.h:69:3: 错误:declaration of ‘dispatcher’ shadows a member of ‘eventpp::ScopedRemover<DispatcherType, typename std::enable_if<std::is_base_of<eventpp::TagEventDispatcher, DispatcherType>::value>::type>’ [-Werror=shadow]
69 | : dispatcher(&dispatcher)
| ^
/home/lianyan/5050pp/libvda5050pp/build/_deps/eventpp-src/include/eventpp/utilities/scopedremover.h:186:19: 附注:被隐藏的声明在这里
186 | DispatcherType * dispatcher;
| ^~~~~~~~~~
/home/lianyan/5050pp/libvda5050pp/build/_deps/eventpp-src/include/eventpp/utilities/scopedremover.h: 在构造函数‘eventpp::ScopedRemover<CallbackListType, typename std::enable_if<std::is_base_of<eventpp::TagCallbackList, CallbackListType>::value>::type>::ScopedRemover(CallbackListType&)’中:
/home/lianyan/5050pp/libvda5050pp/build/_deps/eventpp-src/include/eventpp/utilities/scopedremover.h:210:3: 错误:declaration of ‘callbackList’ shadows a member of ‘eventpp::ScopedRemover<CallbackListType, typename std::enable_if<std::is_base_of<eventpp::TagCallbackList, CallbackListType>::value>::type>’ [-Werror=shadow]
210 | : callbackList(&callbackList)
| ^
/home/lianyan/5050pp/libvda5050pp/build/_deps/eventpp-src/include/eventpp/utilities/scopedremover.h:321:21: 附注:被隐藏的声明在这里
321 | CallbackListType * callbackList;
| ^~~~~~~~~~~~
cc1plus:所有的警告都被当作是错误

how to fix this?

@wqking
Copy link
Owner

wqking commented Mar 29, 2024

The code is pretty legit and the compiler should be able to figure our the proper variable to use to initialize the member.
Also the -Werror=shadow is also a valid option, though it can introduce warning on the code, though it should not be error.
To fix it, you'd either remove -Werror=shadow, or use -Wshadow=local. See this discussion

@lianyant
Copy link
Author

Thank you very much. After commenting out set_compiler_flag ("- Wshadow") in CMakeLists.txt, it can be compiled normally.

@wqking wqking closed this as completed Mar 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants