auto static_cast_warning =
cat("casting to basic_string_view from null is undefined; replace with "
"the empty string");
+ auto argument_construction_warning =
+ cat("passing null as basic_string_view is undefined; replace with the "
+ "empty string");
auto assignment_warning =
cat("assignment to basic_string_view from null is undefined; replace "
"with the default constructor");
auto equality_comparison_warning =
cat("comparing basic_string_view to null is undefined; replace with the "
"emptiness query");
- auto constructor_argument_warning =
- cat("passing null as basic_string_view is undefined; replace with the "
- "empty string");
// Matches declarations and expressions of type `basic_string_view`
auto HasBasicStringViewType = hasType(hasUnqualifiedDesugaredType(recordType(
remove(node("null_arg_expr")), construction_warning);
// `function(null_arg_expr)`
- auto HandleFunctionArgumentInitialization = makeRule(
- callExpr(hasAnyArgument(
- ignoringImpCasts(BasicStringViewConstructingFromNullExpr)),
- unless(cxxOperatorCallExpr())),
- changeTo(node("construct_expr"), cat("{}")), construction_warning);
+ auto HandleFunctionArgumentInitialization =
+ makeRule(callExpr(hasAnyArgument(ignoringImpCasts(
+ BasicStringViewConstructingFromNullExpr)),
+ unless(cxxOperatorCallExpr())),
+ changeTo(node("construct_expr"), cat("\"\"")),
+ argument_construction_warning);
// `sv = null_arg_expr`
auto HandleAssignment = makeRule(
BasicStringViewConstructingFromNullExpr)),
unless(HasBasicStringViewType)),
changeTo(node("construct_expr"), cat("\"\"")),
- constructor_argument_warning);
+ argument_construction_warning);
return applyFirst(
{HandleTemporaryCXXFunctionalCastExpr,
// Function Argument Initialization
{
function(nullptr) /* f1 */;
- // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: constructing{{.*}}default
- // CHECK-FIXES: {{^}} function({}) /* f1 */;
+ // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: passing null as basic_string_view is undefined; replace with the empty string
+ // CHECK-FIXES: {{^}} function("") /* f1 */;
function((nullptr)) /* f2 */;
- // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: constructing{{.*}}default
- // CHECK-FIXES: {{^}} function({}) /* f2 */;
+ // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: passing{{.*}}empty string
+ // CHECK-FIXES: {{^}} function("") /* f2 */;
function({nullptr}) /* f3 */;
- // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: constructing{{.*}}default
- // CHECK-FIXES: {{^}} function({}) /* f3 */;
+ // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: passing{{.*}}empty string
+ // CHECK-FIXES: {{^}} function("") /* f3 */;
function({(nullptr)}) /* f4 */;
- // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: constructing{{.*}}default
- // CHECK-FIXES: {{^}} function({}) /* f4 */;
+ // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: passing{{.*}}empty string
+ // CHECK-FIXES: {{^}} function("") /* f4 */;
function({{}}) /* f5 */; // Default `const CharT*`
- // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: constructing{{.*}}default
- // CHECK-FIXES: {{^}} function({}) /* f5 */;
+ // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: passing{{.*}}empty string
+ // CHECK-FIXES: {{^}} function("") /* f5 */;
}
// Function Argument Initialization With Temporary
struct AcceptsSV {
explicit AcceptsSV(std::string_view) {}
} r1(nullptr);
- // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: passing null as basic_string_view is undefined; replace with the empty string
+ // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: passing{{.*}}empty string
// CHECK-FIXES: {{^}} } r1("");
(void)(AcceptsSV{nullptr}) /* r2 */;