Bug 1441338 - Explicit keyword does not prevent gcc 6.2 from compiling below code
Summary: Explicit keyword does not prevent gcc 6.2 from compiling below code
Keywords:
Status: CLOSED ERRATA
Alias: None
Product: Red Hat Developer Toolset
Classification: Red Hat
Component: gcc
Version: DTS 6.1 RHEL 6
Hardware: All
OS: Linux
unspecified
high
Target Milestone: alpha
: 6.1
Assignee: Marek Polacek
QA Contact: Michael Petlan
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2017-04-11 17:18 UTC by Frank Hirtz
Modified: 2020-12-14 08:30 UTC (History)
7 users (show)

Fixed In Version: devtoolset-7-gcc-7.1.1-7.el7
Doc Type: If docs needed, set a value
Doc Text:
Clone Of:
Environment:
Last Closed: 2017-10-24 09:47:20 UTC
Target Upstream Version:
Embargoed:


Attachments (Terms of Use)


Links
System ID Private Priority Status Summary Last Updated
GNU Compiler Collection 77563 0 None None None 2017-04-11 17:37:17 UTC
Red Hat Product Errata RHEA-2017:3016 0 normal SHIPPED_LIVE new packages: devtoolset-7-gcc 2017-10-24 13:21:49 UTC

Description Frank Hirtz 2017-04-11 17:18:31 UTC
Description of problem:

What problem/issue/behavior are you having trouble with?  What do you expect to see?

I am using dev toolset 6.0. Here is a small reproduction: 
//a.C
#include <string>
#include <iostream>

class Trouble {
  public:
    explicit Trouble(int) { std::cout << "int" << std::endl; }

    Trouble(const char *) { std::cout << "const char*" << std::endl; }
    // Trouble(const signed char *) {}
    Trouble(const unsigned char *) { std::cout << "const unsigned char* " << std::endl;}

  private:
    std::string data;
};

Trouble makeTroubleObject() { return Trouble(42); }
Trouble makeTrouble() { return 42; }

int main()
{
  auto o1 = makeTroubleObject();
  auto o2 = makeTrouble();

  return 0;
}

Build it with
g++ -std=c+=14 -g a.C

I expect I should get a compilation error in this line as the constructor is explicit. 

"Trouble makeTrouble() { return 42; }"

But it compiles fine, and even worse, it seems the object "o2" was not constructed properly thus I got a core dump.


This affects our adoption of Dev toolset 6.0.


Version-Release number of selected component (if applicable):

gcc version 6.2.1 20160916 (Red Hat 6.2.1-3) (GCC) 


How reproducible:

Always

Steps to Reproduce:
1. compile test program
2. execute compiled test
3. boom.

Actual results:

<snip>
[fmhirtz@ivanova ~]$ g++ --std=c++14 -g a.C -g
[fmhirtz@ivanova ~]$ ./a.out 
int
Segmentation fault (core dumped)
</snip>

Expected results:

Compilation failure likely.

Additional info:

This is impacting the client's ability to migrate to DTS6 so it's a priority.

Comment 11 Michael Petlan 2017-09-15 09:19:24 UTC
Successfully reproduced with DTS-6 (no fail) and verified with DTS-7 (devtoolset-7-gcc-7.2.1-1.el{6,7}).

VERIFIED

Comment 13 errata-xmlrpc 2017-10-24 09:47:20 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory, and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

https://access.redhat.com/errata/RHEA-2017:3016


Note You need to log in before you can comment on or make changes to this bug.