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

Warnings due to -Woverloaded-virtual #285

Closed
paragbansal opened this issue Nov 20, 2023 · 3 comments
Closed

Warnings due to -Woverloaded-virtual #285

paragbansal opened this issue Nov 20, 2023 · 3 comments

Comments

@paragbansal
Copy link

paragbansal commented Nov 20, 2023

Compiling with -Woverloaded-virtual fails.

peglib.h:1687:16: warning: 'virtual void peg::Ope::Visitor::visit(peg::Cut&)' was hidden [-Woverloaded-virtual]
 1687 |   virtual void visit(Cut &) {}

peglib.h:1748:8: warning:   by 'peg::AssignIDToDefinition::visit' [-Woverloaded-virtual]
 1748 |   void visit(Recovery &ope) override { ope.ope_->accept(*this); }

peglib.h:1684:16: warning: 'virtual void peg::Ope::Visitor::visit(peg::BackReference&)' was hidden [-Woverloaded-virtual]
 1684 |   virtual void visit(BackReference &) {}

This was reported in #118 as well, but seems like the change got removed. Just wanted to see if any particular reason to?

@yhirose
Copy link
Owner

yhirose commented Nov 20, 2023

@paragbansal thanks for the report, but I am not able to reproduce it on my MacBook. I added -Woverloaded-virtual in CMakeLists.txt as below, and run mkdir build & cd build && cmake .. && make.

image

@paragbansal
Copy link
Author

Thank you @yhirose for having a quick look. I can reproduce using a gcc compiler on Mac.

  1. Install the GCC compiler.

brew install gcc

  1. Make changes in cmake to use gcc compiler instead:
% git diff
diff --git a/CMakeLists.txt b/CMakeLists.txt
index fa15835..59d859c 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1,13 +1,15 @@
 cmake_minimum_required(VERSION 3.14)
-project(peglib)
+set(CMAKE_C_COMPILER /opt/homebrew/Cellar/gcc/13.2.0/bin/gcc-13)
+set(CMAKE_CXX_COMPILER /opt/homebrew/Cellar/gcc/13.2.0/bin/g++-13)
 
+project(peglib)
 set(CMAKE_CXX_STANDARD 17)
 set(CMAKE_CXX_EXTENSIONS OFF)
 
 if(MSVC)
   set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /Zc:__cplusplus /utf-8 /D_CRT_SECURE_NO_DEPRECATE")
 else()
-  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra")
+  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Woverloaded-virtual")
 endif()
 
 set(THREADS_PREFER_PTHREAD_FLAG ON)

  1. Build
 % make 
[  8%] Building CXX object _deps/googletest-build/googletest/CMakeFiles/gtest.dir/src/gtest-all.cc.o
[ 16%] Linking CXX static library ../../../lib/libgtest.a
[ 16%] Built target gtest
[ 25%] Building CXX object _deps/googletest-build/googletest/CMakeFiles/gtest_main.dir/src/gtest_main.cc.o
[ 33%] Linking CXX static library ../../../lib/libgtest_main.a
[ 33%] Built target gtest_main
[ 41%] Building CXX object test/CMakeFiles/peglib-test-main.dir/test1.cc.o
In file included from /Users/paragbansal/cpp-peglib/test/test1.cc:2:
/Users/paragbansal/cpp-peglib/test/../peglib.h:1687:16: warning: 'virtual void peg::Ope::Visitor::visit(peg::Cut&)' was hidden [-Woverloaded-virtual=]
 1687 |   virtual void visit(Cut &) {}
      |                ^~~~~
/Users/paragbansal/cpp-peglib/test/../peglib.h:1748:8: note:   by 'peg::AssignIDToDefinition::visit'
 1748 |   void visit(Recovery &ope) override { ope.ope_->accept(*this); }

@yhirose
Copy link
Owner

yhirose commented Nov 20, 2023

@paragbansal thanks for your help!

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