diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp index b132228b41bb0b49032a6e459332fe9a459de6ad..494ef79cf054ecc3592e00ed83adf7cb281eb2e8 100644 --- a/clang/lib/Sema/SemaExpr.cpp +++ b/clang/lib/Sema/SemaExpr.cpp @@ -5956,11 +5956,13 @@ bool Sema::GatherArgumentsForCall(SourceLocation CallLoc, FunctionDecl *FDecl, const FunctionProtoType *FPT = dyn_cast(Member->getType()); - auto typeQual = FPT->getParamType(0) - .getTypePtr() - ->getPointeeType() - .getCVRQualifiers(); - if (typeQual & Qualifiers::Const || typeQual & Qualifiers::Volatile) { + unsigned CVRQual; + if (FPT->getParamType(0)->isPointerType()) + CVRQual = FPT->getParamType(0) + .getTypePtr() + ->getPointeeType() + .getCVRQualifiers(); + if (CVRQual & Qualifiers::Const || CVRQual & Qualifiers::Volatile) { ImplicitCastExpr *Implict = ImplicitCastExpr::Create( this->Context, FPT->getParamType(0), CK_NoOp, ImplicitArg, nullptr, VK_RValue, FPOptionsOverride()); diff --git a/clang/test/BSC/Method/Struct/struct_static_function_call_by_period.cbs b/clang/test/BSC/Method/Struct/struct_static_function_call_by_period.cbs new file mode 100644 index 0000000000000000000000000000000000000000..d79e28e349bccd14bfa8f2226f70a96b766e55d2 --- /dev/null +++ b/clang/test/BSC/Method/Struct/struct_static_function_call_by_period.cbs @@ -0,0 +1,18 @@ +// RUN: %clang_cc1 -verify %s + +struct S{ + int a; +}; + +struct S struct S::f1(struct S* this) { + return this; // expected-error {{returning 'struct S *' from a function with incompatible result type 'struct S'; dereference with *}} +} + +int struct S::f2(struct S this) { // expected-error {{struct S is not supported on this target}} + return this->a; // expected-error {{member reference type 'struct S' is not a pointer; did you mean to use '.'?}} +} + +void test() { + struct S s1 = {.a = 42}; + int a = s1.f1().f2(); +}