sql-parser icon indicating copy to clipboard operation
sql-parser copied to clipboard

Fix the `'dynamic_cast' not permitted with '-fno-rtti'` error when integrated with LLVM/MLIR.

Open mengke-mk opened this issue 2 years ago • 5 comments

A compile error occurs when including the "SQLParser.h" in another project. (sql_parser as third-party)

/thirdparty/sql-parser/src/sql/CreateStatement.h:74:67: error: 'dynamic_cast' not permitted with '-fno-rtti'
   74 | ynamic_cast<ColumnDefinition*>(tableElem)) {
      |                                         ^

/thirdparty/sql-parser/src/sql/CreateStatement.h:76:82: error: 'dynamic_cast' not permitted with '-fno-rtti'
   76 | dynamic_cast<TableConstraint*>(tableElem)) {
      |                                         ^

Separate the declaration and definition of the setColumnDefsAndConstraints should fix this.

mengke-mk avatar Aug 03 '22 06:08 mengke-mk

Any chance to can provide an example of how to trigger this issue?

Which clang version do you use?

Bouncner avatar Aug 03 '22 09:08 Bouncner

The definition of setColumnDefsAndConstraints is in header file, and it tires to call dynamic_cast. LLVM/MLIR project implicitly add -fno-rtti flag (this flag disable dynamic_cast) and this will cause a compilation error as shown in the title.

Add -fno-rtti in example/Makefile will be an MRE.

#example/Makefile
CFLAGS = -std=c++1z -lstdc++ -Wall -fno-rtti -Werror -I../src/ -L../
all:
     $(CXX) $(CFLAGS) example.cpp -o example -lsqlparser

mengke-mk avatar Aug 03 '22 10:08 mengke-mk

Hi @Bouncner, any chance to get this landed? This fix does not introduce any changes but only removes the function definition from the header file.

mengke-mk avatar Aug 09 '22 02:08 mengke-mk

In the long run, we would like to remove the cluttered statements.cpp. For that, could you please move the function to a new CreateStatement.cpp?

Hi @Bouncner, the above issue has been addressed, PTAL.

mengke-mk avatar Aug 11 '22 03:08 mengke-mk

Feel free to merge.

Bouncner avatar Aug 11 '22 22:08 Bouncner