Closed Bug 1384719 Opened 2 years ago Closed 2 years ago

"error: implicit conversion of nullptr constant to 'bool'" in nsCSSVisitedDependentPropList.h

Categories

(Core :: CSS Parsing and Computation, defect)

defect
Not set

Tracking

()

RESOLVED FIXED
mozilla56
Tracking Status
firefox56 --- fixed

People

(Reporter: botond, Assigned: botond)

References

Details

Attachments

(1 file)

I'm getting the following errors building latest m-c with clang 3.8 and --enable-warnings-as-errors:

 0:26.92 In file included from /home/botond/dev/mozilla/central/objdir-desktop-clang/layout/style/Unified_cpp_layout_style5.cpp:47:
 0:26.92 In file included from /home/botond/dev/mozilla/central/layout/style/nsStyleContext.cpp:366:
 0:26.92 /home/botond/dev/mozilla/central/layout/style/nsCSSVisitedDependentPropList.h:23:153: error: implicit conversion of nullptr constant to 'bool' [-Werror,-Wnull-conversion]
 0:26.92 if (!change && (IsGecko() ? PeekStyleColor() : ((aRelevantStructs & (1 << uint64_t(eStyleStruct_Color))) ? AsServo()->ComputedData()->GetStyleColor() : nullptr))) { const nsStyleColor* thisVisStruct = thisVis->ThreadsafeStyleColor(); const nsStyleColor* otherVisStruct = otherVis->ThreadsafeStyleColor(); if (thisVisStruct->mColor != otherVisStruct->mColor) { change = true; } }
 0:26.92             ~~                                                                                                                                          ^~~~~~~
 0:26.93                                                                                                                                                         false
 0:26.93 /home/botond/dev/mozilla/central/layout/style/nsCSSVisitedDependentPropList.h:24:168: error: implicit conversion of nullptr constant to 'bool' [-Werror,-Wnull-conversion]
 0:26.93 if (!change && (IsGecko() ? PeekStyleBackground() : ((aRelevantStructs & (1 << uint64_t(eStyleStruct_Background))) ? AsServo()->ComputedData()->GetStyleBackground() : nullptr))) { const nsStyleBackground* thisVisStruct = thisVis->ThreadsafeStyleBackground(); const nsStyleBackground* otherVisStruct = otherVis->ThreadsafeStyleBackground(); if (thisVisStruct->mBackgroundColor != otherVisStruct->mBackgroundColor) { change = true; } }
 0:26.93             ~~                                                                                                                                                         ^~~~~~~
 0:26.93                                                                                                                                                                        false
 0:26.93 /home/botond/dev/mozilla/central/layout/style/nsCSSVisitedDependentPropList.h:25:156: error: implicit conversion of nullptr constant to 'bool' [-Werror,-Wnull-conversion]
 0:26.93 if (!change && (IsGecko() ? PeekStyleBorder() : ((aRelevantStructs & (1 << uint64_t(eStyleStruct_Border))) ? AsServo()->ComputedData()->GetStyleBorder() : nullptr))) { const nsStylerTopColor || thisVisStruct->mBorderRightColor != otherVisStruct->mBorderRightColor || thisVisStruct->mBorderBottomColor != otherVisStruct->mBorderBottomColor || thisVisStruct->mBorderLeftCol
 0:26.93             ~~                                                                                                                                             ^~~~~~~
 0:26.93                                                                                                                                                            false
 0:26.93 /home/botond/dev/mozilla/central/layout/style/nsCSSVisitedDependentPropList.h:29:159: error: implicit conversion of nullptr constant to 'bool' [-Werror,-Wnull-conversion]
 0:26.93 if (!change && (IsGecko() ? PeekStyleOutline() : ((aRelevantStructs & (1 << uint64_t(eStyleStruct_Outline))) ? AsServo()->ComputedData()->GetStyleOutline() : nullptr))) { const nsStOutlineColor) { change = true; } }
 0:26.93             ~~                                                                                                                                                ^~~~~~~
 0:26.93                                                                                                                                                               false
 0:26.93 /home/botond/dev/mozilla/central/layout/style/nsCSSVisitedDependentPropList.h:30:156: error: implicit conversion of nullptr constant to 'bool' [-Werror,-Wnull-conversion]
 0:26.93 if (!change && (IsGecko() ? PeekStyleColumn() : ((aRelevantStructs & (1 << uint64_t(eStyleStruct_Column))) ? AsServo()->ComputedData()->GetStyleColumn() : nullptr))) { const nsStylemnRuleColor) { change = true; } }
 0:26.93             ~~                                                                                                                                             ^~~~~~~
 0:26.93                                                                                                                                                            false
 0:26.93 /home/botond/dev/mozilla/central/layout/style/nsCSSVisitedDependentPropList.h:31:150: error: implicit conversion of nullptr constant to 'bool' [-Werror,-Wnull-conversion]
 0:26.93 if (!change && (IsGecko() ? PeekStyleText() : ((aRelevantStructs & (1 << uint64_t(eStyleStruct_Text))) ? AsServo()->ComputedData()->GetStyleText() : nullptr))) { const nsStyleText* r || thisVisStruct->mWebkitTextFillColor != otherVisStruct->mWebkitTextFillColor || thisVisStruct->mWebkitTextStrokeColor != otherVisStruct->mWebkitTextStrokeColor) { change = true; } }
 0:26.93             ~~                                                                                                                                       ^~~~~~~
 0:26.93                                                                                                                                                      false
 0:26.93 /home/botond/dev/mozilla/central/layout/style/nsCSSVisitedDependentPropList.h:34:165: error: implicit conversion of nullptr constant to 'bool' [-Werror,-Wnull-conversion]
 0:26.93 if (!change && (IsGecko() ? PeekStyleTextReset() : ((aRelevantStructs & (1 << uint64_t(eStyleStruct_TextReset))) ? AsServo()->ComputedData()->GetStyleTextReset() : nullptr))) { cons != otherVisStruct->mTextDecorationColor) { change = true; } }
 0:26.93             ~~                                                                                                                                                      ^~~~~~~
 0:26.93                                                                                                                                                                     false
 0:26.93 /home/botond/dev/mozilla/central/layout/style/nsCSSVisitedDependentPropList.h:35:147: error: implicit conversion of nullptr constant to 'bool' [-Werror,-Wnull-conversion]
 0:26.93 if (!change && (IsGecko() ? PeekStyleSVG() : ((aRelevantStructs & (1 << uint64_t(eStyleStruct_SVG))) ? AsServo()->ComputedData()->GetStyleSVG() : nullptr))) { const nsStyleSVG* thisherVisStruct->mStroke) { change = true; } }
 0:26.93             ~~                                                                                                                                    ^~~~~~~
 0:26.93                                                                                                                                                   false
 0:26.93 /home/botond/dev/mozilla/central/layout/style/nsCSSVisitedDependentPropList.h:36:177: error: implicit conversion of nullptr constant to 'bool' [-Werror,-Wnull-conversion]
 0:26.93 if (!change && (IsGecko() ? PeekStyleUserInterface() : ((aRelevantStructs & (1 << uint64_t(eStyleStruct_UserInterface))) ? AsServo()->ComputedData()->GetStyleUserInterface() : nullpStruct->mCaretColor != otherVisStruct->mCaretColor) { change = true; } }
 0:26.93             ~~                                                                                                                                                                  ^~~~~
 0:26.93                                                                                                                                                                                 false
 0:26.93 9 errors generated.
Appears to be a regression from bug 1380133.

Reduced code pattern that triggers the warning:

  $ cat test.cpp
  void foo(bool a, void* b) {
    if (a ? b : nullptr) {}
  }

  $ clang++ -c -std=c++11 -Wall -Werror test.cpp
  test.cpp:2:15: error: implicit conversion of nullptr constant to 'bool' [-Werror,-Wnull-conversion]
    if (a ? b : nullptr) {}
    ~~          ^~~~~~~
                false
  1 error generated.
Blocks: 1380133
Assignee: nobody → botond
Comment on attachment 8890546 [details]
Bug 1384719 - Fix -Wnull-conversion warning in nsStyleContext::CalcStyleDifference().

https://reviewboard.mozilla.org/r/161680/#review167158

Thanks for fixing this.

::: layout/style/nsStyleContext.cpp:357
(Diff revision 1)
>      // |thisVis| (including this function if we skip one of these checks
>      // due to change being true already or due to the old style context
>      // not having a style-if-visited), but not the other way around.
>  #define STYLE_FIELD(name_) thisVisStruct->name_ != otherVisStruct->name_
>  #define STYLE_STRUCT(name_, fields_)                                    \
> -    if (!change && PEEK(name_)) {                                       \
> +    if (!change && (PEEK(name_) != nullptr)) {                                       \

Nit: please fix the alignment of the backslash.
Attachment #8890546 - Flags: review?(cam) → review+
(In reply to Cameron McCormack (:heycam) from comment #3)
> Nit: please fix the alignment of the backslash.

Fixed.
Pushed by bballo@mozilla.com:
https://hg.mozilla.org/integration/autoland/rev/fcae3602b0c3
Fix -Wnull-conversion warning in nsStyleContext::CalcStyleDifference(). r=heycam
https://hg.mozilla.org/mozilla-central/rev/fcae3602b0c3
Status: NEW → RESOLVED
Closed: 2 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla56
You need to log in before you can comment on or make changes to this bug.