Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error in initialization within YY_INITIAL_VALUE() with C++ #442

Closed
matz opened this issue Jun 10, 2024 · 1 comment · Fixed by #443 or #465
Closed

Error in initialization within YY_INITIAL_VALUE() with C++ #442

matz opened this issue Jun 10, 2024 · 1 comment · Fixed by #443 or #465
Labels
bug Something isn't working

Comments

@matz
Copy link

matz commented Jun 10, 2024

In the generated C file, we see YY_INITIAL_VALUE (static YYSTYPE yyval_default;), but clang raises error error: default initialization of an object of const type. According to the C++ language specification, we need a user provided default constructor for this kind of declaration.

Changing the above line to 'YY_INITIAL_VALUE (static YYSTYPE yyval_default;)' as Bison 3.8.2 shows no error.

ydah added a commit to ydah/lrama that referenced this issue Jun 11, 2024
Fix: ruby#442

Before:
```
❯ exe/lrama -d sample/calc.y -o calc.c && cc -Wall calc.c -o calc

❯ exe/lrama -d sample/calc.y -o calc.c && gcc -Wall calc.c -o calc

❯ exe/lrama -d sample/calc.y -o calc.c && c++ -Wall calc.c -o calc
clang: warning: treating 'c' input as 'c++' when in C++ mode, this behavior is deprecated [-Wdeprecated]
calc.c:1199:40: error: default initialization of an object of const type 'const YYSTYPE' without a user-provided default constructor
YY_INITIAL_VALUE (static const YYSTYPE yyval_default;)
```

After:
```
❯ exe/lrama -d sample/calc.y -o calc.c && cc -Wall calc.c -o calc

❯ exe/lrama -d sample/calc.y -o calc.c && gcc -Wall calc.c -o calc

❯ exe/lrama -d sample/calc.y -o calc.c && c++ -Wall calc.c -o calc
clang: warning: treating 'c' input as 'c++' when in C++ mode, this behavior is deprecated [-Wdeprecated]
```
@ydah ydah closed this as completed in #443 Jun 17, 2024
matz added a commit to mruby/mruby that referenced this issue Jun 21, 2024
@matz
Copy link
Author

matz commented Jun 22, 2024

Unfortunately

static const YYSTYPE yyval_default = YY_INITIAL_VALUE(YYSTYPE());

causes compilation error when #define YY_INITIAL_VALUE(Value) /* Nothing. */

error: expected primary-expression before ‘;’ token
 6396 | static const YYSTYPE yyval_default = YY_INITIAL_VALUE(YYSTYPE());
      |                                                                 ^

@matz matz reopened this Jun 22, 2024
matz added a commit to mruby/mruby that referenced this issue Jun 22, 2024
This reverts commit fb9fbc8.

The fix in the upstream still causes syntax error in C++.
@ydah ydah added the bug Something isn't working label Jun 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
2 participants