]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
cobol: Avoid conflict with timespec_t in system headers [PR119217]
authorRainer Orth <ro@CeBiTec.Uni-Bielefeld.DE>
Sun, 13 Apr 2025 10:53:54 +0000 (12:53 +0200)
committerRainer Orth <ro@CeBiTec.Uni-Bielefeld.DE>
Sun, 13 Apr 2025 10:53:54 +0000 (12:53 +0200)
util.cc doesn't compile on Solaris:

/vol/gcc/src/hg/master/local/gcc/cobol/util.cc:2135:7: error: using typedef-name ‘timespec_t’ after ‘class’
 2135 | class timespec_t {
      |       ^~~~~~~~~~

This happens because <time.h> declares timespec_t itself.  In fact,
POSIX.1 reserves every *_t identifier, so this is benign.

To avoid the problem, this patch renames the cobol timespec_t to
cbl_timespec.

Bootstrapped without regressions on amd64-pc-solaris2.11,
sparcv9-sun-solaris2.11, and x86_64-pc-linux-gnu.

2025-04-08  Rainer Orth  <ro@CeBiTec.Uni-Bielefeld.DE>

gcc/cobol:
PR cobol/119217
* util.cc (class timespec_t): Rename to cbl_timespec.

gcc/cobol/util.cc

index f7b89b817cccece3ea39e6a2f655c0dc6250e974..f28fddf6c8f7bdc796fd1b49c61ac6c13ad3d6b8 100644 (file)
@@ -2099,20 +2099,20 @@ cobol_fileline_set( const char line[] ) {
   return file.name;
 }
 
-class timespec_t {
+class cbl_timespec {
   struct timespec now;
  public:
-  timespec_t() {
+  cbl_timespec() {
     clock_gettime(CLOCK_MONOTONIC, &now);
   }
   double ns() const {
     return now.tv_sec * 1000000000 + now.tv_nsec;
   }
-  friend double operator-( const timespec_t& now, const timespec_t& then );
+  friend double operator-( const cbl_timespec& now, const cbl_timespec& then );
 };
 
 double
-operator-( const timespec_t& then, const timespec_t& now ) {
+operator-( const cbl_timespec& then, const cbl_timespec& now ) {
   return (now.ns() - then.ns()) / 1000000000;
 }
 
@@ -2125,11 +2125,11 @@ parse_file( const char filename[] )
 
   parser_enter_file(filename);
 
-  timespec_t start;
+  cbl_timespec start;
 
   int erc = yyparse();
 
-  timespec_t finish;
+  cbl_timespec finish;
   double dt  = finish - start;
   parser_leave_file();