bugGNU roff - Bugs: bug #54702, [grn] "implicit...

 
 

bug #54702: [grn] "implicit fallthrough" warnings from compiler

Submitter:  Bjarni Ingi Gislason <bjarniig>
Submitted:  Thu 20 Sep 2018 11:41:10 PM UTC
   
 
Category:  Preprocessor grn Severity:  2 - Minor
Item Group:  Build/Installation Status:  Fixed
Privacy:  Public Assigned to:  gbranden
Open/Closed:  Closed Planned Release:  1.23.0
* Mandatory Fields

Add a New Comment Rich Markup
   

Thu 02 Jun 2022 09:10:35 PM UTC, comment #4: 

I fixed this differently.


commit d247763cfe9e71fd453ac828d35ab8b207c962fd
Author: G. Branden Robinson <g.branden.robinson@gmail.com>
Date:   Fri Apr 15 09:09:26 2022 +1000

    [grn]: Slightly refactor.

    * src/preproc/grn/hdb.cpp (DBGetType): Lower fatal diagnostics to errors
      when encounting invalid element type characters.  Return a value
      interpreted by our caller as an error indication instead.  Helps
      compilers determine that we're not implicitly falling through our
      cases.  Addresses "-Wimplicit-fallthrough" warnings from GCC.



diff --git a/src/preproc/grn/hdb.cpp b/src/preproc/grn/hdb.cpp
index e8cd9675e..9ba3eaa80 100644
--- a/src/preproc/grn/hdb.cpp
+++ b/src/preproc/grn/hdb.cpp
@@ -325,9 +325,9 @@ DBGetType(char *s)
     case 'R':
       return (CENTRIGHT);
     default:
-      fatal_with_file_and_line(gremlinfile, lineno,
+      error_with_file_and_line(gremlinfile, lineno,
                               "unknown element type '%1'", s);
-      // fatal_with_file_and_line() does not return
+      return -1;
     }
   case 'B':
     switch (s[3]) {
@@ -338,9 +338,9 @@ DBGetType(char *s)
     case 'R':
       return (BOTRIGHT);
     default:
-      fatal_with_file_and_line(gremlinfile, lineno,
+      error_with_file_and_line(gremlinfile, lineno,
                               "unknown element type '%1'", s);
-      // fatal_with_file_and_line() does not return
+      return -1;
     }
   case 'T':
     switch (s[3]) {
@@ -351,16 +351,15 @@ DBGetType(char *s)
     case 'R':
       return (TOPRIGHT);
     default:
-      fatal_with_file_and_line(gremlinfile, lineno,
+      error_with_file_and_line(gremlinfile, lineno,
                               "unknown element type '%1'", s);
-      // fatal_with_file_and_line() does not return
+      return -1;
     }
   default:
-    fatal_with_file_and_line(gremlinfile, lineno,
+    error_with_file_and_line(gremlinfile, lineno,
                             "unknown element type '%1'", s);
+    return -1;
   }
-
-  return 0;                            /* never reached */
 }

 #ifdef UW_FASTSCAN


G. Branden Robinson <gbranden>
Group administrator
Sun 04 Nov 2018 05:55:44 PM UTC, comment #3: 


I used this (Makefile):

CC = /usr/bin/gcc

CFLAGS = -Wall -Wextra -Wformat=2 -Wmissing-prototypes
-Wmissing-declarations -Wold-style-definition -Wstrict-prototypes
-fstack-protector-strong -fno-common -funsigned-char
-fvar-tracking-assignments -O0 -std=c11 -pedantic

CXXFLAGS = -Wall -Wextra -Wformat=2  -fstack-protector-strong
-fno-common -funsigned-char  -O0 -fvar-tracking-assignments


Bjarni Ingi Gislason <bjarniig>
Sun 04 Nov 2018 09:36:47 AM UTC, comment #2: 

I don't see any such warnings on my Debian testing system:

$ gcc --version
gcc (Debian 8.2.0-8) 8.2.0
[...]

  CC       src/utils/xtotroff/xtotroff-xtotroff.o
  CXX      src/preproc/eqn/eqn-main.o
  CXX      src/preproc/grn/hdb.o
  CXX      src/preproc/grn/hpoint.o
  CXX      src/preproc/grn/hgraph.o
  CXX      src/preproc/grn/main.o
  CXX      src/preproc/pic/pic-pic.o

How are you driving the build?

G. Branden Robinson <gbranden>
Group administrator
Fri 21 Sep 2018 12:36:14 AM UTC, comment #1: 


I forgot to add <minus>verbatim<minus> at the end of the original comment.
  Correct the patch as I forgot to add a semicolon after the "return (0)".

From 7403a7a85f4e5fb15b4fc3a039c7f7963570e0f9 Mon Sep 17 00:00:00 2001
From: Bjarni Ingi Gislason <bjarniig@rhi.hi.is>
Date: Fri, 21 Sep 2018 00:05:35 +0000
Subject: [PATCH] hdb.cpp: Add information for the compiler to avoid lack of
 clarity

  A question from the compiler (gcc 8.2) (example):

../src/preproc/grn/hdb.cpp:260:12: warning: this statement may fall through [-Wimplicit-fallthrough=]
       fatal("unknown element type");

  Add an explicit "return", so that the compiler knows that there is no
possibility of a "fallthrough".

Signed-off-by: Bjarni Ingi Gislason <bjarniig@rhi.hi.is>
---
 src/preproc/grn/hdb.cpp | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/src/preproc/grn/hdb.cpp b/src/preproc/grn/hdb.cpp
index fe722c6a..f2463f3c 100644
--- a/src/preproc/grn/hdb.cpp
+++ b/src/preproc/grn/hdb.cpp
@@ -246,6 +246,7 @@ DBGetType(register char *s)
     default:
       fatal("unknown element type");
       // fatal() does not return
+      return (0); // avoid a warning about possible fallthrough
     }
   case 'B':
     switch (s[3]) {
@@ -258,6 +259,7 @@ DBGetType(register char *s)
     default:
       fatal("unknown element type");
       // fatal() does not return
+      return (0); // avoid a warning about a possible fallthrough
     }
   case 'T':
     switch (s[3]) {
@@ -270,6 +272,7 @@ DBGetType(register char *s)
     default:
       fatal("unknown element type");
       // fatal() does not return
+      return (0); // avoid a warning about a possible fallthrough
     }
   default:
     fatal("unknown element type");
--
2.18.0


Bjarni Ingi Gislason <bjarniig>
Thu 20 Sep 2018 11:41:10 PM UTC, original submission:  


From cf3f41f2f36628f994fbd7708ca9efe6ba9fe035 Mon Sep 17 00:00:00 2001
From: Bjarni Ingi Gislason <bjarniig@rhi.hi.is>
Date: Thu, 20 Sep 2018 23:20:26 +0000
Subject: [PATCH] hdb.cpp: Add information for the compiler to avoid lack of
 clarity

  A question from the compiler (gcc 8.2) (example):

../src/preproc/grn/hdb.cpp:260:12: warning: this statement may fall through [-Wimplicit-fallthrough=]
       fatal("unknown element type");

  Add an explicit "return", so that the compiler knows that there is no
possibility of a "fallthrough".

Signed-off-by: Bjarni Ingi Gislason <bjarniig@rhi.hi.is>
---
 src/preproc/grn/hdb.cpp | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/src/preproc/grn/hdb.cpp b/src/preproc/grn/hdb.cpp
index fe722c6a..dbce049c 100644
--- a/src/preproc/grn/hdb.cpp
+++ b/src/preproc/grn/hdb.cpp
@@ -246,6 +246,7 @@ DBGetType(register char *s)
     default:
       fatal("unknown element type");
       // fatal() does not return
+      return (0) // avoid a warning about possible fallthrough
     }
   case 'B':
     switch (s[3]) {
@@ -258,6 +259,7 @@ DBGetType(register char *s)
     default:
       fatal("unknown element type");
       // fatal() does not return
+      return (0) // avoid a warning about a possible fallthrough
     }
   case 'T':
     switch (s[3]) {
@@ -270,6 +272,7 @@ DBGetType(register char *s)
     default:
       fatal("unknown element type");
       // fatal() does not return
+      return (0) // avoid a warning about a possible fallthrough
     }
   default:
     fatal("unknown element type");
--
2.18.0

Bjarni Ingi Gislason <bjarniig>

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by bgarrigues (Updated the item)
  • -email is unavailable- added by gbranden (Posted a comment)
  • -email is unavailable- added by bjarniig (Submitted the item)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only logged-in users can vote.

     

    Follow 13 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2022-06-02 gbranden StatusConfirmed Fixed
        Assigned tobgarrigues gbranden
        Open/ClosedOpen Closed
        Planned ReleaseNone 1.23.0
        Summary[PATCH] [grn] &quot;implicit fallthrough&quot; warnings from compiler [grn] "implicit fallthrough" warnings from compiler
    2022-01-11 gbranden Item GroupWarning/Suspicious behaviour Build/Installation
        Summary[PATCH] hdb.cpp: Add information for the compiler to avoid lack of clarity [PATCH] [grn] "implicit fallthrough" warnings from compiler
    2018-11-26 bgarrigues Severity3 - Normal 2 - Minor
        Item GroupBuild/Installation Warning/Suspicious behaviour
        StatusNeed Info Confirmed
        Assigned toNone bgarrigues
    2018-11-04 gbranden Item GroupNone Build/Installation
        StatusNone Need Info

    Back to the top

    Powered by Savane 3.13-3230.
    Corresponding source code