Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -611,26 +611,21 @@ public final class SwiftModuleBuildDescription {
// suppress warnings if the package is remote
if self.package.isRemote {
// suppress-warnings and the other warning control flags are mutually exclusive
var removeNextArg = false
args = args.filter { arg in
if removeNextArg {
removeNextArg = false
return false
}
var filteredArgs = [String]()
for arg in args {
switch arg {
case "-warnings-as-errors", "-no-warnings-as-errors":
return false
// Skip this flag
continue
case "-Wwarning", "-Werror":
removeNextArg = true
return false
// Remove preceding -Xcc and skip this flag
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rereading this code again, I think this was actually intended to filter out -Werror SwiftWarningGroup (which is also valid) rather than -Xcc -Werror. I think you'll need to examine the preceding arg to check if it's actually -Xcc and therefore safe to remove. If the arg is passed to swiftc directly, the following arg should probably continue to be removed. It would be nice to have some tests for this as well.

Stepping back, this makes me think the compiler should stop diagnosing conflicting flags here and just allow one to win

Copy link
Author

@loonatick-src loonatick-src Sep 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this was actually intended to filter out -Werror SwiftWarningGroup

Ah, I did not know that. Just found -Werror in swiftc --help-hidden.

So, if I understand correctly, the following cases can happen.

  • -Xcc -Werror
  • -Xcc -Werror=<CppWarningGroup>
  • -Werror <SwiftWarningGroup>

and the corresponding Wwarning variants. Anything missing?

Edit: I suppose the complete list is in this proposal.

For C/C++:

  • -Wxxxx
  • -Wno-xxxx
  • -Werror
  • -Werror=xxxx
  • -Wno-error
  • -Wno-error=xxxx

For Swift:

  • -warnings-as-errors
  • -no-warnings-as-errors
  • -Wwarning xxxx
  • -Werror xxxx

Copy link
Author

@loonatick-src loonatick-src Sep 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the compiler should stop diagnosing conflicting flags here and just allow one to win

@owenv If that would be the case, then -suppress-warnings would have to win out over the others for remote packages. But that might not be a good default for non-remote packages.

filteredArgs.removeLast()
default:
return true
filteredArgs.append(arg)
}
}
guard !removeNextArg else {
throw InternalError("Unexpected '-Wwarning' or '-Werror' at the end of args")
}
args += ["-suppress-warnings"]
args = filteredArgs
args.append("-suppress-warnings")
}

// Pass `-user-module-version` for versioned packages that aren't pre-releases.
Expand Down