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

            Bug ID: 98042
           Summary: error diagnostic for unmatched parentheses could be
                    improved
           Product: gcc
           Version: 11.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: tangyixuan at mail dot dlut.edu.cn
  Target Milestone: ---

Hi, the following code is invalid due to the missing of ')' after '*' in Line
4. GCC reports an error which is difficult to understand. Maybe it could be
improved I guess?

$ cat s.cpp
int main (void)
{
  double foo[4096];
  ((char *double(foo))[(sizeof(foo)-1)] = '\0';  // ')' instead of 'double' 
  return 0;
}

$ g++ -c s.cpp
s.cpp: In function ‘int main()’:
s.cpp:4:5: error: expected primary-expression before ‘char’
    4 |   ((char *double(foo))[(sizeof(foo)-1)] = '\0';
      |     ^~~~
s.cpp:4:5: error: expected ‘)’ before ‘char’
    4 |   ((char *double(foo))[(sizeof(foo)-1)] = '\0';
      |    ~^~~~
      |     )
s.cpp:4:47: error: expected ‘)’ before ‘;’ token
    4 |   ((char *double(foo))[(sizeof(foo)-1)] = '\0';
      |   ~                                           ^
      |                                               )

$ clang++ -c s.cpp
s.cpp:4:11: error: expected ')'
  ((char *double(foo))[(sizeof(foo)-1)] = '\0';
          ^
s.cpp:4:4: note: to match this '('
  ((char *double(foo))[(sizeof(foo)-1)] = '\0';
   ^

$ g++ -v
Using built-in specs.
COLLECT_GCC=/usr/local/gcc-20201122/bin/g++
COLLECT_LTO_WRAPPER=/usr/local/gcc-20201122/libexec/gcc/x86_64-pc-linux-gnu/11.0.0/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: ../gcc-11-20201122/configure --prefix=/usr/local/gcc-20201122
--enable-checking=release --enable-languages=c,c++ --disable-multilib
Thread model: posix
Supported LTO compression algorithms: zlib
gcc version 11.0.0 20201122 (experimental) (GCC)

Reply via email to