carbon-lang icon indicating copy to clipboard operation
carbon-lang copied to clipboard

llvm-15: Issue with bison parser.ypp and clang -Wall -Werror

Open malkia opened this issue 3 years ago • 2 comments

I'm on debian 11 (bullseye), which only comes with llvm-11, but installed llvm-15 (and related) through https://apt.llvm.org/

I've almost got explorer working, until I've hit this one:

bazel-out/k8-opt/bin/explorer/syntax/parser.cpp:1050:9: error: variable 'yynerrs_' set but not used [-Werror,-Wunused-but-set-variable]

then googled and found possible solution (possible, because I don't know if it's right)

malkia@penguin:~/p/carbon-language/carbon-lang$ git diff
diff --git a/explorer/syntax/parser.ypp b/explorer/syntax/parser.ypp
index 79e9357..df3fdae 100644
--- a/explorer/syntax/parser.ypp
+++ b/explorer/syntax/parser.ypp
@@ -91,6 +91,13 @@
   }
 }  // %code
 
+%code {
+#if defined(__clang__)
+// Clang warns that the variable 'yynerrs_' is set but not used.
+#pragma clang diagnostic ignored "-Wunused-but-set-variable"
+#endif
+}
+
 %token <int> integer_literal
 %token <std::string> identifier
 %token <IntrinsicExpression::Intrinsic> intrinsic_identifier

It now compiles :) - but haven't it run it yet! Thanks for this exciting new language!

malkia avatar Jul 24 '22 15:07 malkia

Do you still have this problem if you use a homebrew installation of llvm instead of the apt-provided one?

geoffromer avatar Jul 25 '22 20:07 geoffromer

I suspect this is due to the use of llvm-15; annotated. llvm-15 isn't stable yet, but this may just be newer error detection changes, so it's still worth fixing this for when it's eventually fixed.

jonmeow avatar Jul 30 '22 23:07 jonmeow