Bug 1715391

Summary: Build on gcc8 errors with catching polymorphic type ‘class ResourceMonitor::RMException’ by value
Product: Red Hat Enterprise Linux 8 Reporter: Prabhanjan Gururaj <prabhanjan.gururaj>
Component: gccAssignee: Marek Polacek <mpolacek>
gcc sub component: system-version QA Contact: qe-baseos-tools-bugs
Status: CLOSED NOTABUG Docs Contact:
Severity: high    
Priority: unspecified CC: ahajkova, fweimer, jakub, ohudlick
Version: 8.2   
Target Milestone: rc   
Target Release: 8.0   
Hardware: x86_64   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2019-06-04 21:19:25 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description Prabhanjan Gururaj 2019-05-30 08:59:51 UTC
Description of problem:
g++ fails as below:
error: catching polymorphic type ‘class ResourceMonitor::RMException’ by value [-Werror=catch-value=]
     } catch (ResourceMonitor::RMException rme) {


Version-Release number of selected component (if applicable):
Red Hat Enterprise Linux 8.0 Beta (Ootpa)
kernel-4.18.0-74.el8.x86_64
gcc-c++-8.2.1-3.5.el8.x86_64
gcc-8.2.1-3.5.el8.x86_64


Details:
g++  -Wall -Werror -DLINUX -fpic -I/usr/include/libnl3 -I/usr/include -Ih/linux -Ih -Iobjs/product -Ideadman_module -Icfs/cmvxd -DSACTO -DQS -DENABLE_ENHANCED_SECURITY  -Wno-deprecated -c -o objs/product/DiskAgentMain.o resserv/agents/disk/DiskAgentMain.cpp

Putting child 0x55d32b299460 (objs/product/DiskAgentMain.o) PID 18102 on the chain.
Live child 0x55d32b299460 (objs/product/DiskAgentMain.o) PID 18102

resserv/agents/disk/DiskAgentMain.cpp: In function ‘int main(int, const char**, const char**)’:
resserv/agents/disk/DiskAgentMain.cpp:12:43: error: catching polymorphic type ‘class ResourceMonitor::RMException’ by value [-Werror=catch-value=]
     } catch (ResourceMonitor::RMException rme) {
                                           ^~~
cc1plus: all warnings being treated as errors
Reaping losing child 0x55d32b299460 PID 18102


Expected results:
The same piece of code is getting built successfully on gcc 4.8. I am seeing this issue only after moving to gcc8.2 with rhel8. 

Additional info:
I see a similar error being posted in https://bugzilla.redhat.com/show_bug.cgi?id=1542888, but for qpid/fedora.

Comment 1 Jakub Jelinek 2019-05-30 09:19:53 UTC
You are compiling with -Wall -Werror, so you need to be prepared to deal with new warnings that through those command line options are turned into errors.
-Wcatch-value is a new warning, introduced in GCC 8, so no wonder you haven't seen such a warning with GCC 4.8.
Either don't use -Werror, use -Wno-catch-value, disable the warning for the particular spot with #pragma GCC diagnostic or change the code.

The warning is documented as:
'-Wcatch-value'
'-Wcatch-value=N (C++ and Objective-C++ only)'
     Warn about catch handlers that do not catch via reference.  With
     '-Wcatch-value=1' (or '-Wcatch-value' for short) warn about
     polymorphic class types that are caught by value.  With
     '-Wcatch-value=2' warn about all class types that are caught by
     value.  With '-Wcatch-value=3' warn about all types that are not
     caught by reference.  '-Wcatch-value' is enabled by '-Wall'.

See also https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#e15-catch-exceptions-from-a-hierarchy-by-reference for rationale for that warning.

Comment 2 Prabhanjan Gururaj 2019-05-30 10:52:38 UTC
Thanks Jakub. It helped.

Comment 3 Marek Polacek 2019-06-04 21:19:25 UTC
Not a GCC bug.