[Bug c++/89232] New: c++: Fail to build when and the noreturn keyword is used

2019-02-06 Thread pere at hungry dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=89232

Bug ID: 89232
   Summary: c++: Fail to build when  and the
noreturn keyword is used
   Product: gcc
   Version: 8.2.1
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: pere at hungry dot com
  Target Milestone: ---

I ran into this issue while trying to prepare the coz profiler for Debian.

The  header file seem to be inefficient when using cc and
clang, be ignored causing an build error when using c++.

I found this example code on
http://en.cppreference.com/w/c/language/_Noreturn >, and it fail
to build with c++, but build with both cc and clang:

% cat > c++-noreturn.c <
#include 
#include 

// causes undefined behavior if i <= 0
// exits if i > 0
noreturn void stop_now(int i) // or _Noreturn void stop_now(int i)
{
if (i > 0) exit(i);
}

int main(void)
{
  puts("Preparing to stop...");
  stop_now(2);
  puts("This code is never executed.");
}
EOF
% gcc c++-noreturn.c 
c++-noreturn.c: In function 'stop_now':
c++-noreturn.c:10:1: warning: 'noreturn' function does return
 }
 ^
% ./a.out 
Preparing to stop...
% c++ c++-noreturn.c 
c++-noreturn.c:7:1: error: 'noreturn' does not name a type
 noreturn void stop_now(int i) // or _Noreturn void stop_now(int i)
 ^~~~
c++-noreturn.c: In function 'int main()':
c++-noreturn.c:15:13: error: 'stop_now' was not declared in this scope
   stop_now(2);
 ^
% clang c++-noreturn.c 
c++-noreturn.c:10:1: warning: function declared 'noreturn' should not return
[-Winvalid-noreturn]
}
^
1 warning generated.
%

Perhaps something that should be fixed?

This issue is also reported as https://bugs.debian.org/833931 and has been
present since at least gcc 6.  I find
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=53182 related to the user of
, but it seem to be a different issue.

-- 
Happy hacking
Petter Reinholdtsen

[Bug c++/89232] c++: Fail to build when and the noreturn keyword is used

2019-02-07 Thread pere at hungry dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=89232

--- Comment #2 from pere at hungry dot com ---
Aha.  I thought valid C code would also be valid C++ code, and this belief
became stronger when clang (and clang++) would accept the code.  Is there a
list of C headers not supported by C++?

[Bug c++/89232] c++: Fail to build when and the noreturn keyword is used

2019-02-08 Thread pere at hungry dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=89232

--- Comment #5 from pere at hungry dot com ---
Thank you for the explanation.  It is a lot clearer to me now.

One thing confuses me, though.  If  is not acceptable in C++,
why is there no warning from the compiler when it is included, instead of
giving the strange complain when 'noreturn' is used later in the file.

[Bug c++/89232] c++: Fail to build when and the noreturn keyword is used

2019-02-08 Thread pere at hungry dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=89232

--- Comment #7 from pere at hungry dot com ---
I just think it would have been useful if the compiler said something
like 'header file  is not defined/available in C++' or
something like that.  It would provide feedback to the developer even if
'noreturn' is not used anywhere in the code to cause the error I ran
into.

Anywya, just an idea for you to consider, perhaps a feature request for
a different bug report. :)

[Bug c/11250] -pedantic accepts `char a[] = ("x");'

2004-10-28 Thread pere at hungry dot com

--- Additional Comments From pere at hungry dot com  2004-10-28 09:15 ---
The compiler on IA64/HP-UX (aCC: HP aC++/ANSI C B3910B A.05.50 [May 15 2003])
refuses to compile this code and gives this error message:

  Error 271: "x.c", line 1 # Illegal initializer.
  char a[] = ("x");
 ^

It would be good if GCC always gave a warning (or even an error) if this
code is illegal according to ANSI C, to warn people that this code will fail
to compile on other compilers.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=11250