From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 43F5D393C843; Sun, 18 Apr 2021 09:56:07 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 43F5D393C843 From: "patrick.kox at commandoregel dot be" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/100135] New: ICE when using constants in a mdoule Date: Sun, 18 Apr 2021 09:56:07 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c++ X-Bugzilla-Version: 11.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: patrick.kox at commandoregel dot be X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 18 Apr 2021 09:56:07 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D100135 Bug ID: 100135 Summary: ICE when using constants in a mdoule Product: gcc Version: 11.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: patrick.kox at commandoregel dot be Target Milestone: --- Using the following code from the book (Professional C++ 5th Edition) by Ma= rc Grergoire causes an ICE when trying to compile the "Employee" module. I have 2 files: Employee.cpp (the Interface, called Employee.cppm in the book): =3D=3D=3D export module employee; import; namespace Records { const int DefaultStartingSalary{30'000}; export const int DefaultRaiseAndDemeritAmount{1'000}; export class Employee{ public: Employee(const std::string& firstName, const std::string& lastName); void promote(int raiseAmount =3D DefaultRaiseAndDemeritAmount); void demote(int demeritAmount =3D DefaultRaiseAndDemeritAmount); void hire(); // Hires or rehires the employee void fire(); // Dismisses the employee void display() const; // Display employee information on the cons= ole // Getters and setters void setFirstName(const std::string& firstName); const std::string& getFirstName() const; void setLastName(const std::string& lastName); const std::string& getLastName() const; void setEmployeeNumber(int employeeNumber); int getEmployeeNumber()const; void setSalary(int salary); int getSalary()const; bool isHired() const; private: std::string m_firstName; std::string m_lastName; int m_employeeNumber{-1}; int m_salary{DefaultStartingSalary}; bool m_hired{false}; }; } =3D=3D=3D And Employee-i.cpp (called Employee.cpp in the book): =3D=3D=3D module employee; import; //import ; // Not Available using namespace std; namespace Records { Employee::Employee(const string& firstName, const string& lastName) : m_firstName{firstName}, m_lastName{lastName} { } void Employee::promote(int raiseAmount) { setSalary(getSalary() + raiseAmount); } void Employee::demote(int demeritAmount) { setSalary(getSalary() - demeritAmount); } void Employee::hire() { m_hired =3D true; } void Employee::fire() { m_hired =3D false; } void Employee::display() const { cout << "Employee: " << getLastName() << ", " << getFirstName() << endl; cout << "-------------------------" << endl; cout << (isHired() ? "Current employee" : "Former employee") << end= l; cout << "Employee number: " << getEmployeeNumber() << endl; cout << "Salary: $" << getSalary() << endl; cout << endl; } // Getters and setters void Employee::setFirstName(const string& firstName) { m_firstName =3D firstName; } const string& Employee::getFirstName() const { return m_firstName; } void Employee::setLastName(const string& lastName) { m_lastName =3D lastName; } const string& Employee::getLastName() const { return m_lastName; } void Employee::setEmployeeNumber(int employeeNumber) { m_employeeNumber =3D employeeNumber; } int Employee::getEmployeeNumber() const { return m_employeeNumber; } void Employee::setSalary(int salary) { m_salary =3D salary; } int Employee::getSalary() const { return m_salary; } bool Employee::isHired() const { return m_hired; } } =3D=3D=3D Note: import ; is commented out since this module is not available = yet (the code is also modified to use the "old cout" syntax and not the new format(""); syntax. The error message thie causes is: Employee.cpp:19:14: error: =E2=80=98void Records::Employee::promote(int)=E2= =80=99 references internal linkage entity =E2=80=98const int Records::DefaultRaiseAndDemeritA= mount=E2=80=99 19 | void promote(int raiseAmount =3D DefaultRaiseAndDemeritAmou= nt); | ^~~~~~~ Employee.cpp:20:14: error: =E2=80=98void Records::Employee::demote(int)=E2= =80=99 references internal linkage entity =E2=80=98const int Records::DefaultRaiseAndDemeritA= mount=E2=80=99 20 | void demote(int demeritAmount =3D DefaultRaiseAndDemeritAmo= unt); | ^~~~~~ Employee.cpp:15:14: error: =E2=80=98class Records::Employee=E2=80=99 refere= nces internal linkage entity =E2=80=98const int Records::DefaultStartingSalary=E2=80=99 15 | export class Employee{ | ^~~~~~~~ Employee.cpp:4:8: error: failed to write compiled module: Bad file data 4 | export module employee; | ^~~~~~ Employee.cpp:4:8: note: compiled module file is =E2=80=98gcm.cache/employee= .gcm=E2=80=99 In module imported at Employee-i.cpp:5:1: employee: error: failed to read compiled module: No such file or directory employee: note: compiled module file is =E2=80=98gcm.cache/employee.gcm=E2= =80=99 employee: note: imports must be built before being imported employee: fatal error: returning to the gate for a mechanical issue compilation terminated. make: *** [Makefile:55: gcm] Error 1=