Fix unused variable warnings across code generators

Removing `_LIBCPP_DISABLE_UNUSED_STRUCT_WARNINGS` from libc++ enables
`[[gnu::__warn_unused__]]` on standard library types (such as
`std::string` and `std::set`), surfacing `-Wunused-variable` warnings.
See [upstream LLVM commit](https://github.com/llvm/llvm-project/commit/ab8b037ef7b398aa864959a69f328fa69b567f74) for reference.

- Remove unreferenced variable declarations whose initializers have no
  side effects (`generated_functions`, `offset_prefix`, `offset_size`,
  `filebase`, `field_name`, `offset`, `ts_file_path_rel`,
  `ts_file_path`, and `union_accessor`).
- Annotate variables initialized via helper or member calls with
  `[[maybe_unused]]` (`offset_str`, `get_field`, `qualified`,
  `struct_var`, `struct_type`, `type`, `def_mod_name`, and
  `ts_file_path`).

PiperOrigin-RevId: 999136370
This commit is contained in:
Anshul Nigham
2026-10-23 18:40:05 +00:00
committed by Derek Bailey
parent 6dda43bbaa
commit 9698e11376
10 changed files with 9 additions and 25 deletions
+1 -2
View File
@@ -2737,7 +2737,6 @@ class CppGenerator : public BaseGenerator {
if (!field.IsScalarOptional()) {
const bool is_scalar = IsScalar(type.base_type);
std::string accessor;
std::string offset_size = "";
if (is_scalar) {
accessor = "GetField<";
} else if (IsStruct(type)) {
@@ -2815,7 +2814,7 @@ class CppGenerator : public BaseGenerator {
void GenTableFieldType(const FieldDef& field) {
const auto& type = field.value.type;
const auto offset_str = GenFieldOffsetName(field);
[[maybe_unused]] const auto offset_str = GenFieldOffsetName(field);
if (!field.IsScalarOptional()) {
std::string afterptr = " *" + NullableExtension();
code_.SetValue("FIELD_TYPE",