[llvm-bugs] [Bug 46339] New: Weird error messages in different versions of clang or in a newline

via llvm-bugs llvm-bugs at lists.llvm.org
Mon Jun 15 23:36:42 PDT 2020


https://bugs.llvm.org/show_bug.cgi?id=46339

            Bug ID: 46339
           Summary: Weird error messages in different versions of clang or
                    in a newline
           Product: clang
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Frontend
          Assignee: unassignedclangbugs at nondot.org
          Reporter: haoxintu at gmail.com
                CC: llvm-bugs at lists.llvm.org, neeilans at live.com,
                    richard-llvm at metafoo.co.uk

These cases make clang emitting different error messages. I think it's so weird
and I guess there might be somethings wrong with clang's parser. The only
difference between test1.cc and test2.cc is I make line3 and line4 together in
test2.cc and let them sperateted in test1.cc.

$cat test1.cc
bool var_bool;
void a() {
    b <volatile >enum c 
    union  { static_assert  ( var_bool , "" )}
}

$cat test2.cc
bool var_bool;
void a() {
    b <volatile >enum c union  { static_assert  ( var_bool , "" )}
}


$ clang++-trunk -w -c test1.cc 
test1.cc:3:17: error: expected a type
    b <volatile >enum c 
                ^
test1.cc:3:24: error: expected ';' after enum
    b <volatile >enum c 
                       ^
                       ;
test1.cc:3:23: error: ISO C++ forbids forward references to 'enum' types
    b <volatile >enum c 
                      ^
test1.cc:4:46: error: expected ';' after static_assert
    union  { static_assert  ( var_bool , "" )}
                                             ^
                                             ;
test1.cc:4:31: error: static_assert expression is not an integral constant
expression
    union  { static_assert  ( var_bool , "" )}
                              ^~~~~~~~
test1.cc:4:31: note: read of non-const variable 'var_bool' is not allowed in a
constant expression
test1.cc:1:6: note: declared here
bool var_bool;
     ^
test1.cc:4:47: error: expected ';' after union
    union  { static_assert  ( var_bool , "" )}
                                              ^
                                              ;
6 errors generated.

$ clang++-trunk -w -c test2.cc 
test2.cc:3:17: error: expected a type
    b <volatile >enum c union  { static_assert  ( var_bool , "" )}
                ^
test2.cc:3:23: error: ISO C++ forbids forward references to 'enum' types
    b <volatile >enum c union  { static_assert  ( var_bool , "" )}
                      ^
test2.cc:4:1: error: expected unqualified-id
}
^
3 errors generated.

While in clang-10 or lower versions, both test1.cc or test2.cc produce the same
results. Take clang-10 for example,

$clang++-10 -w -c test1.cc
test1.cc:3:17: error: expected a type
    b <volatile >enum c 
                ^
1 error generated.

$clang++-10 -w -c test2.cc
test1.cc:3:17: error: expected a type
    b <volatile >enum c 
                ^
1 error generated.

$clang++-trunk --version
clang version 11.0.0 (https://github.com/llvm/llvm-project
e6aba43cda848f4a8cfa5ce9f174b77def10e9df)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /home/haoxin/compilers/llvm-clang/llvm-project/build/bin

So, My concerns are
1. Why clang-trunk treats test1.cc and test2.cc differently just because of an
EOL?
2. The compiled results are inconsistent between clang-trunk and other clang
versions.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20200616/6fbda6e2/attachment.html>


More information about the llvm-bugs mailing list