Menu

syntax parsing - enum in classes

2023-01-13
2023-01-15
  • Daniel Black

    Daniel Black - 2023-01-13

    I haven't yet got a simple reproducer yet.
    https://github.com/MariaDB/server/blob/10.11/sql/sql_class.h#L334

    sql/sql_class.h:334:3: error: syntax error [syntaxError]
    enum drop_type { KEY, COLUMN, FOREIGN_KEY, CHECK_CONSTRAINT, PERIOD };
    ^

     
  • CHR

    CHR - 2023-01-13

    It seems that the error is produced by a file that includes sql_class.h. Can you narrow it down that way?

     
  • Daniel Black

    Daniel Black - 2023-01-15
    using std::trunc;
     
      enum
      {
          FE_INVALID = 1
        };
    
    $ bin/cppcheck /tmp/x.c++
    Checking /tmp/x.c++ ...
    /tmp/x.c++:4:3: error: syntax error: 16 = [syntaxError]
      {
      ^
    

    Error from:

    Tokenizer::findGarbageCode (this=0x7fffffff97a0) at /home/dan/repos/cppcheck/lib/tokenize.cpp:7597
    7597                syntaxError(tok, tok->next()->str() + " " + tok->strAt(2));
    

    This is from:

    #include <math.h>
    #include <fenv.h>
    

    And also:

      struct __true_type { };
     
        template<typename _Tp>
          struct __is_move_iterator
          {
            enum { __value = 0 };
          };
     
     
        template<typename _Iterator>
          class move_iterator;
     
      template<typename _Iterator>
          struct __is_move_iterator<move_iterator<_Iterator> >
          {
            enum { __value = 1 };
            typedef __true_type __type;
          };
     
      # 272 "/usr/include/c++/12/bits/cpp_type_traits.h" 3
    __extension__ template<> struct s { enum { __value = 1 }; };
    
    /tmp/x.c++:21:15: error: syntax error [syntaxError]
    __extension__ template<> struct s { enum { __value = 1 }; };
    

    __extension__ appears straight ignorable - https://gcc.gnu.org/onlinedocs/gcc/Alternate-Keywords.html#index-_005f_005fextension_005f_005f

     
  • Daniel Black

    Daniel Black - 2023-01-15

    reproduceable (preprocessed, not minimized, and slow):

    I assume there's a way to take output at stages:

    $ time bin/cppcheck --language=c++   --report-progress  ~/repos/build-mariadb-server-10.11/libmysqld/CMakeFiles/sql_embedded.dir/emb_qcache.cc.ii
    Checking /home/dan/repos/build-mariadb-server-10.11/libmysqld/CMakeFiles/sql_embedded.dir/emb_qcache.cc.ii ...
    progress: Tokenize (typedef) 0%
    progress: Tokenize (typedef) 0%
    progress: Tokenize (typedef) 1%
    progress: Tokenize (typedef) 5%
    progress: Tokenize (typedef) 5%
    progress: Tokenize (typedef) 7%
    progress: Tokenize (typedef) 9%
    progress: Tokenize (typedef) 10%
    progress: Tokenize (typedef) 10%
    progress: Tokenize (typedef) 11%
    progress: Tokenize (typedef) 12%
    progress: Tokenize (typedef) 20%
    progress: Tokenize (typedef) 38%
    progress: Tokenize (typedef) 62%
    progress: Tokenize (typedef) 73%
    progress: Tokenize (typedef) 74%
    progress: Tokenize (using) 12%
    progress: TemplateSimplifier::simplifyTemplateInstantiations() 84%
    progress: TemplateSimplifier::simplifyTemplateInstantiations() 88%
    progress: TemplateSimplifier::simplifyTemplateInstantiations() 92%
    progress: TemplateSimplifier::simplifyTemplateInstantiations() 95%
    progress: TemplateSimplifier::simplifyTemplateInstantiations() 68%
    progress: TemplateSimplifier::simplifyTemplateInstantiations() 20%
    progress: TemplateSimplifier::simplifyTemplateInstantiations() 99%
    progress: TemplateSimplifier::simplifyTemplateInstantiations() 8%
    progress: TemplateSimplifier::simplifyTemplateInstantiations() 2%
    progress: Tokenize (using) 99%
    progress: Tokenize (using) 99%
    progress: Tokenize (using) 99%
    progress: Tokenize (using) 99%
    progress: Tokenize (using) 99%
    progress: Tokenize (using) 99%
    progress: Tokenize (using) 99%
    progress: Tokenize (using) 99%
    progress: Tokenize (using) 99%
    progress: Tokenize (using) 99%
    progress: Tokenize (using) 99%
    progress: Tokenize (using) 99%
    progress: Tokenize (using) 99%
    progress: Tokenize (using) 99%
    progress: Tokenize (using) 99%
    progress: Tokenize (using) 99%
    progress: Tokenize (using) 99%
    progress: TemplateSimplifier::simplifyTemplateInstantiations() 18%
    progress: Tokenize (using) 99%
    progress: Tokenize (using) 99%
    progress: SymbolDatabase 0%
    /home/dan/repos/mariadb-server-10.11/sql/sql_class.h:334:3: error: syntax error [syntaxError]
      enum drop_type { KEY, COLUMN, FOREIGN_KEY, CHECK_CONSTRAINT, PERIOD };
      ^
    
    real    10m7.423s
    user    10m4.766s
    sys 0m1.478s
    
     
  • CHR

    CHR - 2023-01-15

    As you noted, there is a clash between FE_INVALID from the enum and fenv.h/std.cfg.
    __extension__ is handled by adding --library=gnu.
    I have created a ticket for the third issue: https://trac.cppcheck.net/ticket/11494

     
  • Daniel Black

    Daniel Black - 2023-01-15

    Thank you.

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.