Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

__declspec properties outside of class members do not work as expected #90743

Open
kodenamekrak opened this issue May 1, 2024 · 3 comments · Fixed by QuestPackageManager/cordl#9
Labels
clang:frontend Language frontend issues, e.g. anything involving "Sema" confirmed Verified by a second party extension:microsoft

Comments

@kodenamekrak
Copy link

kodenamekrak commented May 1, 2024

As shown in the example below, the properties return unexpected results when used outside of class members.
Although, according to Microsoft's specification, they shouldnt be allowed outside of members and should cause error C3065

https://godbolt.org/z/jqe59vW85

#include <cstdio>

struct Color {
    float r, g, b, a;
};

struct Test {
    Color get_value() {
        return Color{1.0f, 0.5f, 0.5f, 1.0f};
    }
    __declspec(property(get=get_value)) Color value;
};

Color get_value() {
    return Color{1.0f, 0.5f, 0.5f, 1.0f};
}
__declspec(property(get=get_value)) Color value;

int main() {
    Test t;

    auto color2 = t.value;
	printf("%f, %f, %f, %f\n", color2.r, color2.g, color2.b, color2.a);

    // returns empty ?
    auto color3 = value;
	printf("%f, %f, %f, %f\n", color3.r, color3.g, color3.b, color3.a);

    auto color4 = get_value();
	printf("%f, %f, %f, %f\n", color4.r, color4.g, color4.b, color4.a);

    return 0;
}
1.000000, 0.500000, 0.500000, 1.000000
0.000000, 0.000000, 0.000000, 0.000000
1.000000, 0.500000, 0.500000, 1.000000
@EugeneZelenko EugeneZelenko added clang:frontend Language frontend issues, e.g. anything involving "Sema" extension:microsoft and removed new issue labels May 1, 2024
@llvmbot
Copy link
Member

llvmbot commented May 1, 2024

@llvm/issue-subscribers-clang-frontend

Author: None (kodenamekrak)

As shown in the example below, the properties return unexpected results when used outside of class members. Although, according to [Microsoft's specification](https://learn.microsoft.com/en-us/cpp/cpp/property-cpp?view=msvc-170), they shouldnt be allowed outside of members and should cause [error C3065](https://learn.microsoft.com/en-us/cpp/error-messages/compiler-errors-2/compiler-error-c3065?view=msvc-170)

https://godbolt.org/z/jqe59vW85

#include &lt;cstdio&gt;

struct Color {
    float r, g, b, a;
};

struct Test {
    Color get_value() {
        return Color{1.0f, 0.5f, 0.5f, 1.0f};
    }
    __declspec(property(get=get_value)) Color value;
};

Color get_value() {
    return Color{1.0f, 0.5f, 0.5f, 1.0f};
}
__declspec(property(get=get_value)) Color value;

int main() {
    Test t;

    auto color2 = t.value;
	printf("%f, %f, %f, %f\n", color2.r, color2.g, color2.b, color2.a);

    // returns empty ?
    auto color3 = value;
	printf("%f, %f, %f, %f\n", color3.r, color3.g, color3.b, color3.a);

    auto color4 = get_value();
	printf("%f, %f, %f, %f\n", color4.r, color4.g, color4.b, color4.a);

    return 0;
}
1.000000, 0.500000, 0.500000, 1.000000
0.000000, 0.000000, 0.000000, 0.000000
1.000000, 0.500000, 0.500000, 1.000000

@shafik
Copy link
Collaborator

shafik commented May 1, 2024

CC @AaronBallman

@AaronBallman AaronBallman added the confirmed Verified by a second party label May 16, 2024
@AaronBallman
Copy link
Collaborator

Different godbolt link: https://godbolt.org/z/eEjTEE6f1

Clang should reject this, same as MSVC.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:frontend Language frontend issues, e.g. anything involving "Sema" confirmed Verified by a second party extension:microsoft
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants