62 lines · cpp
1// RUN: %clang_analyze_cc1 -analyzer-checker=core.DivideZero -std=c++20 -verify %s2 3namespace GH148875 {4struct A {5 int x;6 A(int v) : x(v) {}7};8 9struct B {10 int x;11 B() : x(0) {}12};13 14struct C {15 int x, y;16 C(int a, int b) : x(a), y(b) {}17};18 19struct D {20 int x;21};22 23struct E {24 D d;25 E(int a) : d(a) {}26};27 28struct F {29 int x;30};31 32int t1() {33 A a{42};34 return 1 / (a.x - 42); // expected-warning {{Division by zero}}35}36 37int t2() {38 B b{};39 return 1 / b.x; // expected-warning {{Division by zero}}40}41 42int t3() {43 C c1{1, -1};44 return 1 / (c1.x + c1.y); // expected-warning {{Division by zero}}45}46 47int t4() {48 C c2{0, 0};49 return 1 / (c2.x + c2.y); // expected-warning {{Division by zero}}50}51 52int t5() {53 E e{32};54 return 1 / (e.d.x - 32); // expected-warning {{Division by zero}}55}56 57int t6() {58 F f(32);59 return 1 / (f.x - 32); // expected-warning {{Division by zero}}60}61} // namespace GH14887562