Skip to content

Fix @__ctfe being lost on template functions - #23943

Merged
dkorpel merged 1 commit into
dlang:masterfrom
TurkeyMan:pr1_ctfe_syntaxcopy
Sep 29, 2026
Merged

dkorpel merged 1 commit into
dlang:masterfrom
TurkeyMan:pr1_ctfe_syntaxcopy

Conversation

@TurkeyMan

Copy link
Copy Markdown
Contributor

TypeFunction.syntaxCopy did not copy isCtfeOnly

Comment on lines +1 to +20
/*
TEST_OUTPUT:
---
fail_compilation/test_ctfe_attribute_template.d(19): Error: function `test_ctfe_attribute_template.add!int` is `@__ctfe` and cannot be used at runtime
---
*/

// `@__ctfe` on a template function was lost when the declaration was copied for instantiation

T add(T)(T a, T b) @__ctfe
{
return a + b;
}

enum three = add!int(1, 2); // fine

void main()
{
auto x = add!int(1, 2);
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this test be merged with fail_compilation/test_ctfe_attribute_glue.d?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it can

@dkorpel dkorpel added the Backport:v2.114 Cherry-pick this PR onto the v2.114 release branch label Sep 29, 2026
TypeFunction.syntaxCopy did not copy isCtfeOnly, so a template function
declared @__ctfe was code generated and callable at runtime once
instantiated.
@TurkeyMan
TurkeyMan force-pushed the pr1_ctfe_syntaxcopy branch 2 times, most recently from c2e6150 to 8560ad2 Compare September 29, 2026 14:43
@dkorpel
dkorpel merged commit 95711ee into dlang:master Sep 29, 2026
42 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Backport:v2.114 Cherry-pick this PR onto the v2.114 release branch

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants