public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "patrick.kox at commandoregel dot be" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [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)
Date: Wed, 24 Mar 2021 11:46:03 +0000	[thread overview]
Message-ID: <bug-99749-4@http.gcc.gnu.org/bugzilla/> (raw)

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

             reply	other threads:[~2021-03-24 11:46 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-24 11:46 patrick.kox at commandoregel dot be [this message]
2024-03-06 20:31 ` [Bug c++/99749] " ppalka at gcc dot gnu.org

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-99749-4@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).