Skip to content

Commit

Permalink
Fix an error for initialization within YY_INITIAL_VALUE() with C++
Browse files Browse the repository at this point in the history
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]
```
  • Loading branch information
ydah committed Jun 11, 2024
1 parent 9a75458 commit be9b052
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions template/bison/yacc.c
Original file line number Diff line number Diff line change
Expand Up @@ -1475,7 +1475,11 @@ int yychar;
/* The semantic value of the lookahead symbol. */
/* Default value used for initialization, for pacifying older GCCs
or non-GCC compilers. */
#ifdef __cplusplus
static const YYSTYPE yyval_default = YY_INITIAL_VALUE(YYSTYPE());
#else
YY_INITIAL_VALUE (static const YYSTYPE yyval_default;)
#endif
YYSTYPE yylval YY_INITIAL_VALUE (= yyval_default);

/* Location data for the lookahead symbol. */
Expand Down

0 comments on commit be9b052

Please sign in to comment.