public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/99749] New: Error when using std::string in a module (versions 11.0.1 20210307, 11.0.1 20210314, and 11.0.1 20210321)
@ 2021-03-24 11:46 patrick.kox at commandoregel dot be
  2024-03-06 20:31 ` [Bug c++/99749] " ppalka at gcc dot gnu.org
  0 siblings, 1 reply; 2+ messages in thread
From: patrick.kox at commandoregel dot be @ 2021-03-24 11:46 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99749

            Bug ID: 99749
           Summary: Error when using std::string in a module (versions
                    11.0.1 20210307, 11.0.1 20210314, and 11.0.1 20210321)
           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: ---

Created attachment 50468
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=50468&action=edit
AirlineTicket example code from Professional C++ 5th Edition

When trying to compile the "AirlineTicket" example/exercise from the book
Professional C++ (5th edition by Marc Gregoire) I'm getting the following error
message when I use a std::string in my module.

The complete error is:
---------------------
In file included from /opt/gcc-11/include/c++/11.0.1/string:55,
of module /opt/gcc-11/include/c++/11.0.1/string, imported at
AirlineTicket.cpp:3,
of module airline_ticket, imported at main.cpp:2:
/opt/gcc-11/include/c++/11.0.1/bits/basic_string.h: In function ‘int main()’:
/opt/gcc-11/include/c++/11.0.1/bits/basic_string.h:431:7: error:
‘std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::basic_string() [with
_CharT = char; _Traits = std::char_traits<char>; _Alloc =
std::allocator<char>]’ cannot be overloaded with
‘std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::basic_string() [with
_CharT = char; _Traits = std::char_traits<char>; _Alloc =
std::allocator<char>]’
  431 |       basic_string()
      |       ^~~~~~~~~~~~
In file included from /opt/gcc-11/include/c++/11.0.1/string:55,
                 from /opt/gcc-11/include/c++/11.0.1/bits/locale_classes.h:40,
                 from /opt/gcc-11/include/c++/11.0.1/bits/ios_base.h:41,
                 from /opt/gcc-11/include/c++/11.0.1/ios:42,
                 from /opt/gcc-11/include/c++/11.0.1/ostream:38,
                 from /opt/gcc-11/include/c++/11.0.1/iostream:39,
of module /opt/gcc-11/include/c++/11.0.1/iostream, imported at main.cpp:1:
/opt/gcc-11/include/c++/11.0.1/bits/basic_string.h:431:7: note: previous
declaration ‘std::__cxx11::basic_string<_CharT, _Traits,
_Alloc>::basic_string() [with _CharT = char; _Traits = std::char_traits<char>;
_Alloc = std::allocator<char>]’
  431 |       basic_string()
      |       ^~~~~~~~~~~~
In file included from /opt/gcc-11/include/c++/11.0.1/string:55,
of module /opt/gcc-11/include/c++/11.0.1/string, imported at
AirlineTicket.cpp:3,
of module airline_ticket, imported at main.cpp:2:
/opt/gcc-11/include/c++/11.0.1/bits/basic_string.h:431:7: error:
‘std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::basic_string() [with
_CharT = char; _Traits = std::char_traits<char>; _Alloc =
std::allocator<char>]’ cannot be overloaded with
‘std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::basic_string() [with
_CharT = char; _Traits = std::char_traits<char>; _Alloc =
std::allocator<char>]’
  431 |       basic_string()
      |       ^~~~~~~~~~~~
In file included from /opt/gcc-11/include/c++/11.0.1/string:55,
                 from /opt/gcc-11/include/c++/11.0.1/bits/locale_classes.h:40,
                 from /opt/gcc-11/include/c++/11.0.1/bits/ios_base.h:41,
                 from /opt/gcc-11/include/c++/11.0.1/ios:42,
                 from /opt/gcc-11/include/c++/11.0.1/ostream:38,
                 from /opt/gcc-11/include/c++/11.0.1/iostream:39,
of module /opt/gcc-11/include/c++/11.0.1/iostream, imported at main.cpp:1:
/opt/gcc-11/include/c++/11.0.1/bits/basic_string.h:431:7: note: previous
declaration ‘std::__cxx11::basic_string<_CharT, _Traits,
_Alloc>::basic_string() [with _CharT = char; _Traits = std::char_traits<char>;
_Alloc = std::allocator<char>]’
  431 |       basic_string()
      |       ^~~~~~~~~~~~
main.cpp:6:9: note: during load of binding ‘::AirlineTicket@airline_ticket’
    6 |         AirlineTicket myTicket;
      |         ^~~~~~~~~~~~~
make: *** [Makefile:76: debug] Error 1
---------------------

The code that I'm using is:
---------------------
export module airline_ticket;

import<string>;

export class AirlineTicket{
public:
        AirlineTicket();
        ~AirlineTicket();

        double calculatePriceInDollars()const;

        std::string getPassengerName()const;
        void setPassengerName(std::string name);

        int getNumberOfMiles() const;
        void setNumberOfMiles(int miles);

        bool hasEliteSuperRewardsStatus() const;
        void setHasEliteSuperRecardsStatus(bool status);

private:
        std::string m_passengerName{};
        int m_numberOfMiles{};
        bool m_hasEliteSuperRewardsStatus{};
};

AirlineTicket::AirlineTicket() : m_passengerName{"Unknown Passenger"},
m_numberOfMiles{0},m_hasEliteSuperRewardsStatus{false}{}

AirlineTicket::~AirlineTicket() {}
double AirlineTicket::calculatePriceInDollars() const
{
        if (hasEliteSuperRewardsStatus()) {
                // Elite Super Rewards Customers fly for free.
                return 0;       
        }
        // The cost of a ticket is the number of miles times 0.1.
        // Real airlines probably have  a more complicated
        // formula!

        return getNumberOfMiles() * 0.1;
}
std::string AirlineTicket::getPassengerName()const {
        return m_passengerName;
}
void AirlineTicket::setPassengerName(std::string name)
{
        m_passengerName = name;
}
void AirlineTicket::setPassengerInitial(char initial)
{
        m_passengerInitial = initial;
}
int AirlineTicket::getNumberOfMiles() const
{
        return m_numberOfMiles;
}
void AirlineTicket::setNumberOfMiles(int miles)
{
        m_numberOfMiles = miles;
}
bool AirlineTicket::hasEliteSuperRewardsStatus() const
{
        return m_hasEliteSuperRewardsStatus;
}
void AirlineTicket::setHasEliteSuperRecardsStatus(bool status)
{
        m_hasEliteSuperRewardsStatus = status;
}
---------------------

When I remove the string from the code, it compiles without problem, also when
I use a string in main() there is no error.

Also the following 2 compile commands run without problem:
g++  -Wall -Wextra -fmodules-ts -std=gnu++20 -pedantic -c -x c++-system-header
iostream string
and
g++ -Wall -Wextra -fmodules-ts -std=gnu++20 -pedantic -c AirlineTicket.cpp

I've attached a tarball with the AirlineTicket.cpp and main.cpp files

^ permalink raw reply	[flat|nested] 2+ messages in thread

* [Bug c++/99749] Error when using std::string in a module (versions 11.0.1 20210307, 11.0.1 20210314, and 11.0.1 20210321)
  2021-03-24 11:46 [Bug c++/99749] New: Error when using std::string in a module (versions 11.0.1 20210307, 11.0.1 20210314, and 11.0.1 20210321) patrick.kox at commandoregel dot be
@ 2024-03-06 20:31 ` ppalka at gcc dot gnu.org
  0 siblings, 0 replies; 2+ messages in thread
From: ppalka at gcc dot gnu.org @ 2024-03-06 20:31 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99749

Patrick Palka <ppalka at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |FIXED
             Status|UNCONFIRMED                 |RESOLVED
                 CC|                            |ppalka at gcc dot gnu.org
   Target Milestone|---                         |11.0

--- Comment #1 from Patrick Palka <ppalka at gcc dot gnu.org> ---
This seems long fixed, even GCC 11 is happy.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2024-03-06 20:31 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-24 11:46 [Bug c++/99749] New: Error when using std::string in a module (versions 11.0.1 20210307, 11.0.1 20210314, and 11.0.1 20210321) patrick.kox at commandoregel dot be
2024-03-06 20:31 ` [Bug c++/99749] " ppalka at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).