Remove misc GCC-related compiler warnings.
When building GN with GCC, several warnings are printed
by the compiler about minor issues. This CL fixes these.
- src/gn/desc_builder.cc, src/gn/parser.cc, src/gn/visibility.cc:
Remove redundant std::move() in return statements. These are
harmless, except that they prevent copy-elision optimization
in the generated code.
- src/gn/target.cc: Remove the unused 'rstool' variable.
- src/gn/pointer_set.h: Call the base default constructor
explicitly in the PointerSet copy-constructor. Note that
this is the default compiler behaviour, so this doesn´t
change the generated code.
- src/base/compiler_specific.h: Update the FALLTHROUGH macro
definition for C++17, removing a compiler warning in
src/base/json/json_parser.cc.
Bug: None
Change-Id: I098f5edcf95f82cdfef0161cc637711111a3ff42
Reviewed-on: https://gn-review.googlesource.com/c/gn/+/12820
Reviewed-by: Brett Wilson <brettw@chromium.org>
Commit-Queue: David Turner <digit@google.com>
diff --git a/src/base/compiler_specific.h b/src/base/compiler_specific.h
index b788a8c..ec139d2 100644
--- a/src/base/compiler_specific.h
+++ b/src/base/compiler_specific.h
@@ -56,7 +56,9 @@
#endif // !defined(LIKELY)
// Macro for telling -Wimplicit-fallthrough that a fallthrough is intentional.
-#if defined(__clang__)
+#if __cplusplus >= 201703L
+#define FALLTHROUGH [[fallthrough]]
+#elif defined(__clang__)
#define FALLTHROUGH [[clang::fallthrough]]
#else
#define FALLTHROUGH
diff --git a/src/gn/desc_builder.cc b/src/gn/desc_builder.cc
index 5a8fc4c..444a5e0 100644
--- a/src/gn/desc_builder.cc
+++ b/src/gn/desc_builder.cc
@@ -136,7 +136,7 @@
for (const auto& v : vector)
res->Append(RenderValue(v));
- return std::move(res);
+ return res;
}
ValuePtr RenderValue(const std::string& s, bool optional = false) {
@@ -712,7 +712,7 @@
}
}
- return std::move(res);
+ return res;
}
ValuePtr RenderGenDeps() {
@@ -724,7 +724,7 @@
std::sort(gen_deps.begin(), gen_deps.end());
for (const auto& dep : gen_deps)
res->AppendString(dep);
- return std::move(res);
+ return res;
}
ValuePtr RenderRuntimeDeps() {
@@ -750,7 +750,7 @@
res->AppendString(str + pair.first.value());
}
- return std::move(res);
+ return res;
}
void FillInSourceOutputs(base::DictionaryValue* res) {
diff --git a/src/gn/parser.cc b/src/gn/parser.cc
index dbc3d62..a4ad244 100644
--- a/src/gn/parser.cc
+++ b/src/gn/parser.cc
@@ -472,7 +472,7 @@
std::unique_ptr<BlockCommentNode> comment =
std::make_unique<BlockCommentNode>();
comment->set_comment(token);
- return std::move(comment);
+ return comment;
}
std::unique_ptr<ParseNode> Parser::Group(const Token& token) {
@@ -495,7 +495,7 @@
std::unique_ptr<UnaryOpNode> unary_op = std::make_unique<UnaryOpNode>();
unary_op->set_op(token);
unary_op->set_operand(std::move(expr));
- return std::move(unary_op);
+ return unary_op;
}
std::unique_ptr<ParseNode> Parser::List(const Token& node) {
@@ -521,7 +521,7 @@
binary_op->set_op(token);
binary_op->set_left(std::move(left));
binary_op->set_right(std::move(right));
- return std::move(binary_op);
+ return binary_op;
}
std::unique_ptr<ParseNode> Parser::IdentifierOrCall(
@@ -562,7 +562,7 @@
func_call->set_args(std::move(list));
if (block)
func_call->set_block(std::move(block));
- return std::move(func_call);
+ return func_call;
}
std::unique_ptr<ParseNode> Parser::Assignment(std::unique_ptr<ParseNode> left,
@@ -583,7 +583,7 @@
assign->set_op(token);
assign->set_left(std::move(left));
assign->set_right(std::move(value));
- return std::move(assign);
+ return assign;
}
std::unique_ptr<ParseNode> Parser::Subscript(std::unique_ptr<ParseNode> left,
@@ -603,7 +603,7 @@
std::unique_ptr<AccessorNode> accessor = std::make_unique<AccessorNode>();
accessor->set_base(left->AsIdentifier()->value());
accessor->set_subscript(std::move(value));
- return std::move(accessor);
+ return accessor;
}
std::unique_ptr<ParseNode> Parser::DotOperator(std::unique_ptr<ParseNode> left,
@@ -629,7 +629,7 @@
accessor->set_base(left->AsIdentifier()->value());
accessor->set_member(std::unique_ptr<IdentifierNode>(
static_cast<IdentifierNode*>(right.release())));
- return std::move(accessor);
+ return accessor;
}
// Does not Consume the start or end token.
@@ -699,7 +699,7 @@
// ignorant of them.
AssignComments(file.get());
- return std::move(file);
+ return file;
}
std::unique_ptr<ParseNode> Parser::ParseStatement() {
@@ -769,7 +769,7 @@
}
if (has_error())
return std::unique_ptr<ParseNode>();
- return std::move(condition);
+ return condition;
}
void Parser::TraverseOrder(const ParseNode* root,
diff --git a/src/gn/pointer_set.h b/src/gn/pointer_set.h
index b690ace..6dc18b4 100644
--- a/src/gn/pointer_set.h
+++ b/src/gn/pointer_set.h
@@ -63,7 +63,7 @@
PointerSet() = default;
// Allow copying pointer sets.
- PointerSet(const PointerSet& other) { insert(other); }
+ PointerSet(const PointerSet& other) : BaseType() { insert(other); }
PointerSet& operator=(const PointerSet& other) {
if (this != &other) {
this->~PointerSet();
diff --git a/src/gn/target.cc b/src/gn/target.cc
index ded575a..508ad7e 100644
--- a/src/gn/target.cc
+++ b/src/gn/target.cc
@@ -996,7 +996,7 @@
SubstitutionWriter::ApplyListToLinkerAsOutputFile(
this, tool, tool->runtime_outputs(), &runtime_outputs_);
}
- } else if (const RustTool* rstool = tool->AsRust()) {
+ } else if (tool->AsRust()) {
// Default behavior, use the first output file for both.
link_output_file_ = dependency_output_file_ =
SubstitutionWriter::ApplyPatternToLinkerAsOutputFile(
diff --git a/src/gn/visibility.cc b/src/gn/visibility.cc
index 8fb5e7f..0878990 100644
--- a/src/gn/visibility.cc
+++ b/src/gn/visibility.cc
@@ -84,7 +84,7 @@
auto res = std::make_unique<base::ListValue>();
for (const auto& pattern : patterns_)
res->AppendString(pattern.Describe());
- return std::move(res);
+ return res;
}
// static