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

            Bug ID: 87351
           Summary: misleading error message: missing binary operator
                    before token "("
           Product: gcc
           Version: 9.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: preprocessor
          Assignee: unassigned at gcc dot gnu.org
          Reporter: vincent-gcc at vinc17 dot net
  Target Milestone: ---

The error message

  error: missing binary operator before token "("

from the preprocessor is misleading in general, as in most cases, it is not a
binary operator that is missing, but the error is due to the use of sizeof, a
cast, or a function-like macro that is not defined. The preprocessor could
either output a fixed error message that would reflect the most common
misusages, or try to guess what is wrong (like the use of sizeof or something
that looks like a cast).

For instance:

$ cat tst.c
#if sizeof(int) > 4
#endif
$ gcc-snapshot -E tst.c
# 1 "tst.c"
# 1 "<built-in>"
# 1 "<command-line>"
# 31 "<command-line>"
# 1 "/usr/include/stdc-predef.h" 1 3 4
# 32 "<command-line>" 2
# 1 "tst.c"
tst.c:1:11: error: missing binary operator before token "("
1 | #if sizeof(int) > 4
  |           ^

Some users can get confused. For instance, see:
*
https://stackoverflow.com/questions/21338385/what-does-the-compiler-error-missing-binary-operator-before-token-mean
*
https://cboard.cprogramming.com/c-programming/158452-error-missing-binary-operator-before-token.html
*
https://www.linuxquestions.org/questions/programming-9/missing-binary-operator-before-token-4175547706/
* https://forum.kde.org/viewtopic.php?f=269&t=128141

Reply via email to