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

            Bug ID: 90005
           Summary: No error produced for the wrong type of string used in
                    gcc >= 5.0
           Product: gcc
           Version: 8.3.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: pawel.wrobel at nielsen dot com
  Target Milestone: ---

Hello,

I have the question regarding the following behaviour of gcc 8.3 (it behaves
the same way from version 5.0 up to 8.3 - when I tested with the
https://gcc.godbolt.org/).

When I compile following program (it has an obvious omission - missing .c_str()
conversion of std::string to char*) 

    #include <stdio.h>
    #include <string>
    int main()
    { 
      std::string txt("there");
      printf("Hello %s ! \n", txt);
    }

On the gcc 4.9 and before - it correctly notifies me with an error like : 

<source>: In function 'int main()':

<source>:6:30: error: cannot pass objects of non-trivially-copyable type
'std::string {aka class std::basic_string<char>}' through '...'
   printf("Hello %s ! \n", txt);
Compiler returned: 1



However, starting from the gcc 5.0 and above (gcc 8.3 included) - no error is
generated - and the binary is being produced. It obviously prints the garbage
when run ("Hello (`e !"). So lack of the error should be considered as an bug ?
Or maybe do I need to provide some special flag for this error message to
appear and stop the compilation in gcc 5.0 and above ? 
Both the gcc <= 4.9 works correctly here (and the newer clang compilers also
point out this error correctly). Can I make the gcc >= 5.0 to generate an error
here with some flag ?

Reply via email to