New issue
Advanced search Search tips
Note: Color blocks (like or ) mean that a user may not be available. Tooltip shows the reason.

Issue 602217 link

Starred by 1 user

Issue metadata

Status: WontFix
Owner:
Last visit 26 days ago
Closed: Apr 2016
Cc:
EstimatedDays: ----
NextAction: ----
OS: All
Pri: 2
Type: Bug



Sign in to add a comment

GN: incorrect "unused variable" errors

Project Member Reported by sdefresne@chromium.org, Apr 11 2016

Issue description

The following code incorrectly report the "removed_configs" are unused (see  bug 602209  for the reason why I have to use "removed_configs"):

template("wrapped_shared_library") {
  shared_library(target_name) {
    forward_variables_from(invoker, "*", ["configs"])
    if (defined(invoker.configs)) {
      configs += invoker.configs
    }
    if (defined(invoker.removed_configs)) {
      configs -= invoker.removed_configs
    }
  }
}

wrapped_shared_library("foo") {
  sources = ["bar.cc", "bar.h"]
  removed_configs = [
    "//build/config/gcc:symbol_visibility_hidden"
  ]
}

Causes the following error while I expect the variable to be marked as used by the template "configs -= remove_unused":

$ gn gen out/gn
ERROR at //foo/BUILD.gn:16:21: Assignment had no effect.
  removed_configs = [
                    ^
You set the variable "removed_configs" here and it was unused before it went
out of scope.
See //foo/BUILD.gn:14:1: whence it was called.
wrapped_shared_library("foo") {
^------------------------------

Note that the removed value is present (this command is run with "removed_configs = ..." line commented out):

$ gn desc out/gn //foo configs
  //build/config:feature_flags
  //build/config/compiler:compiler
  //build/config/compiler:clang_stackrealign
  //build/config/compiler:compiler_arm_fpu
  //build/config/compiler:chromium_code
  //build/config/compiler:default_include_dirs
  //build/config/compiler:default_optimization
  //build/config/compiler:default_symbols
  //build/config/compiler:no_rtti
  //build/config/compiler:runtime_library
  //build/config/sanitizers:default_sanitizer_flags
  //build/config/sanitizers:default_sanitizer_coverage_flags
  //build/config/gcc:no_exceptions
  //build/config/gcc:symbol_visibility_hidden
  //build/config/clang:find_bad_constructs
  //build/config/clang:extra_warnings
  //build/config:debug
  //build/config:default_libs
  //build/config:shared_library_config

 

Comment 1 by brettw@chromium.org, Apr 11 2016

This is coming from the shared_library. forward_variables_from is forwarding it there and then it's unused. You should exclude this from the list like you did with configs (from the other bug I'm guessing you'll be changing this all around anyway).
Status: WontFix (was: Assigned)
Oh, it make sense then, I guess it is a PEBKAC. Marking as WontFix.

Sign in to add a comment