Commit graph

565 commits

Author SHA1 Message Date
abul
ddb917f8e8 Template function named argument error messages 2025-04-21 07:01:22 +08:00
Nick Treleaven
011c27165e
Fix wrong 'not an lvalue' error when assigning to sequence (#21260)
Fixes #21259.
2025-04-18 20:29:13 +08:00
Abul Hossain Khan
bc3c423fd7
Fix error location for binary operations to point at operator instead of first operand (#21253) 2025-04-18 07:24:30 +08:00
Abhay Pratap
513293b0d8
dcast.d: Improve pointer conversion error messages (#21221) 2025-04-15 18:03:44 +08:00
drpriver
f4ca164257
Fix #20499 - [ImportC] typedef struct with name as a pointer cannot be used with struct name (#21232)
Fixes https://github.com/dlang/dmd/issues/20499
Fixes https://github.com/dlang/dmd/issues/20963

ImportC deferred declaring "tagged" types (structs/unions/enums)
until after it saw a possible typedef so that the identifier for
a typedef declaration like:

    typedef struct { int x; } Foo;

would give the struct the name Foo. In several circumstances,
this led to tagged types not being declared. Resolve this by
chasing down those circumstances.

Also, there were other circumstances where types weren't being
correctly declared which caused other issues. Lock those down.
2025-04-15 15:31:21 +08:00
Abul Hossain Khan
d0cf2c7117
Add Testcases For other Fixed issues (#21231) 2025-04-14 23:17:17 +02:00
Abul Hossain Khan
d657667ff8
Report correct location for undefined identifiers in function return types (#21223) 2025-04-14 16:08:52 +08:00
drpriver
8a8746f318
Fix 18127 - ImportC: redeclaration of struct in different translation unit doesn’t check compatibility (#21224)
Fixes: https://github.com/dlang/dmd/issues/18127

When merging struct definitions from different C imports, check that the
structs are actually compatible according to the C rules. If they are
not, issue an error.
2025-04-14 14:35:20 +08:00
Martin Kinkelin
58d065f935 Merge remote-tracking branch 'origin/stable'
Conflicts:
	compiler/src/dmd/declaration.h
	compiler/src/dmd/frontend.h
	compiler/src/dmd/globals.h
	compiler/src/dmd/typesem.d
	compiler/src/tests/cxxfrontend.cc
	compiler/test/fail_compilation/fail347.d
2025-04-11 13:35:53 +02:00
drpriver
a0bf0f368a
ImportC: allow _Alignof expression (#21181)
Resolves https://github.com/dlang/dmd/issues/20434

Allowing this gnu/clang extension actually removes lines of code as
we can unify the parsing and semantics of `_Alignof` and `sizeof`
and have the normal D machinery handle the difference later.
2025-04-10 07:20:50 +08:00
Dennis
0aee4697bd
Fix #21189 - wrong/missing error line when source file isn't regular (#21190) 2025-04-10 07:19:58 +08:00
drpriver
74cdfed9d6
ImportC: improve error message for size_t (#21187)
Resolves: https://github.com/dlang/dmd/issues/20414

Add some hints for common missing includes.
2025-04-10 07:16:54 +08:00
drpriver
7dd0506aaf
Fix #21150 - ImportC: alignment value expected, not _Alignof (#21180)
The gnu attribute aligned() allows specifying the alignment of an entire
struct, mostly as a syntatic convenience. This attribute allows
compile-time integer expressions, but the parser was trying to evaluate them
ahead of time by checking for an integer literal. Instead we need to
preserve the expression and defer it to a later semantic stage.
Accomplish this by emulating the behavior by specifying the alignment of
the first member of the struct.

I didn't change how __declspec(align(#)) parses as from the
documentation it seems to only allow integer literals. Some light
testing with cl.exe gives syntax errors when trying to use _Alignof() in
that position.
2025-04-09 10:59:26 +08:00
Abul Hossain Khan
a03aa271f8
Improve override suggestions to exclude final methods (#21138) 2025-04-07 14:09:25 +08:00
Dennis
4d0934d37f
merge stable (#21127)
* bump VERSION to v2.110.0

* purge changelog

* bump VERSION to v2.111.0-beta.1

* Accept __rvalue attribute on ref functions; which will force the result to be treated as __rvalue. (#20946)

This is essential to implement `move`, `forward`, etc.

* memoryerror.d: Fix AnySupported version condition (#20983)

* Fix #20982 - wrong line number in iasmgcc (#20993)

* Move genCfunc to cxxfrontend (#20992)

* druntime: Fix compilation of rt.cover on Android (#21015)

* Expose SourceLoc to C++ interface (#20980)

* [stable] C++ header fixes for declaration, expression, and typinf (#21016)

Seen either from compilation errors or missing symbols at link time.

* C++ headers: Add 3 Declaration bitfield setters/getters required by LDC

* druntime: Add module declaration to rt.invariant, to prevent conflicts with user-provided invariant.d (#21017)

* Fix #21020 - Indexing a *cast* AA yields no lvalue anymore (#21029)

* Add C++23 to CppStdRevision enum (#21043)

* Improve UFCS/property error message (#21046)

* bump VERSION to v2.111.0-rc.1

* Fix #21045 - import __stdin causes compilation to pause while reading from stdin (#21047)

Moves the special handling of reading from stdin out of the semantic
routines to the DMD driver itself. All references to `__stdin.d` have
also been removed from the frontend implementation.

* Update source code and coverage links (#21111)

* Fix #21024 - Optimize x^^c expressions (#21082)

* Fix #21024 - Optimize x^^c expressions

Reason for the *magic* constraint c<8 on inlining x^^c:

https://sourceware.org/git/?p=glibc.git;a=blob;f=sysdeps/x86_64/fpu/e_powl.S;h=47f129f34d368d7c67b8e5f2462b36b0bebb7621;hb=HEAD#l136

* Fix poor assumption about expression state

* Restrict optimization to floating point expressions

* Generalize optimization to any scalar data type

* Fix segfault on x^^c where x is a single member anonymous enum

DMD segfaulted on compiling the unittests in std/algorithm/sorting.o, the
unittest that caused the segfault can be reduced to:

    enum real Two = 2.0;
    auto _ = Two^^3;

I'm not sure why copying the anonymous enum into a `const` variable causes
the compiler to segfault.

* Add tests to x^^c inlining optimization

* Fix missing type for e1 ^^ -1 to 1 / e1 rewrite

* Move rewrites from constant folding to expression semantic and restrict them to [-1, 2]

* Improve error message for the x^^2 rewrite.

Before:
    ex.d(4): Error: can implicitly convert expression `(const const(double) __powtmp2 = x + 5.0;) , __powtmp2 * ...` of type `double` to `int`
        int y = ( x + 5 ) ^^ 2;
                ^
and after:
    ex.d(4): Error: cannot implicitly convert expression `(x + 5.0) ^^ 2L` of type `double` to `int`
        int y = ( x + 5 ) ^^ 2;
                ^

* Update C++ frontend header to match change in `CommaExp`

* Address code review feedback

Co-authored-by: Dennis Korpel <dkorpel@gmail.com>

---------

Co-authored-by: Dennis Korpel <dkorpel@gmail.com>

* Revert "Fix #21024 - Optimize x^^c expressions (#21082)" (#21114)

This reverts commit fa1f860e4b.

* bump VERSION to v2.111.0

* purge changelog

* Strip trailing newline off sarif version

---------

Co-authored-by: Manu Evans <turkeyman@gmail.com>
Co-authored-by: Martin Kinkelin <kinke@users.noreply.github.com>
Co-authored-by: Iain Buclaw <ibuclaw@gdcproject.org>
Co-authored-by: Martin Kinkelin <noone@nowhere.com>
Co-authored-by: Fares A. Bakhit <faresa.bakhit@gmail.com>
2025-03-31 15:54:53 +02:00
Dennis
95fdc47f5f
Fix #21024 - Optimize x^^c expressions (#21082) (#21115)
* Fix #21024 - Optimize x^^c expressions

Reason for the *magic* constraint c<8 on inlining x^^c:

https://sourceware.org/git/?p=glibc.git;a=blob;f=sysdeps/x86_64/fpu/e_powl.S;h=47f129f34d368d7c67b8e5f2462b36b0bebb7621;hb=HEAD#l136

* Fix poor assumption about expression state

* Restrict optimization to floating point expressions

* Generalize optimization to any scalar data type

* Fix segfault on x^^c where x is a single member anonymous enum

DMD segfaulted on compiling the unittests in std/algorithm/sorting.o, the
unittest that caused the segfault can be reduced to:

    enum real Two = 2.0;
    auto _ = Two^^3;

I'm not sure why copying the anonymous enum into a `const` variable causes
the compiler to segfault.

* Add tests to x^^c inlining optimization

* Fix missing type for e1 ^^ -1 to 1 / e1 rewrite

* Move rewrites from constant folding to expression semantic and restrict them to [-1, 2]

* Improve error message for the x^^2 rewrite.

Before:
    ex.d(4): Error: can implicitly convert expression `(const const(double) __powtmp2 = x + 5.0;) , __powtmp2 * ...` of type `double` to `int`
        int y = ( x + 5 ) ^^ 2;
                ^
and after:
    ex.d(4): Error: cannot implicitly convert expression `(x + 5.0) ^^ 2L` of type `double` to `int`
        int y = ( x + 5 ) ^^ 2;
                ^

* Update C++ frontend header to match change in `CommaExp`

* Address code review feedback



---------

Co-authored-by: Fares A. Bakhit <faresa.bakhit@gmail.com>
2025-03-29 13:57:10 +01:00
Dennis
8dcef66a5f
Revert "Fix #21024 - Optimize x^^c expressions (#21082)" (#21114)
This reverts commit fa1f860e4b.
2025-03-29 12:25:53 +01:00
Fares A. Bakhit
fa1f860e4b
Fix #21024 - Optimize x^^c expressions (#21082)
* Fix #21024 - Optimize x^^c expressions

Reason for the *magic* constraint c<8 on inlining x^^c:

https://sourceware.org/git/?p=glibc.git;a=blob;f=sysdeps/x86_64/fpu/e_powl.S;h=47f129f34d368d7c67b8e5f2462b36b0bebb7621;hb=HEAD#l136

* Fix poor assumption about expression state

* Restrict optimization to floating point expressions

* Generalize optimization to any scalar data type

* Fix segfault on x^^c where x is a single member anonymous enum

DMD segfaulted on compiling the unittests in std/algorithm/sorting.o, the
unittest that caused the segfault can be reduced to:

    enum real Two = 2.0;
    auto _ = Two^^3;

I'm not sure why copying the anonymous enum into a `const` variable causes
the compiler to segfault.

* Add tests to x^^c inlining optimization

* Fix missing type for e1 ^^ -1 to 1 / e1 rewrite

* Move rewrites from constant folding to expression semantic and restrict them to [-1, 2]

* Improve error message for the x^^2 rewrite.

Before:
    ex.d(4): Error: can implicitly convert expression `(const const(double) __powtmp2 = x + 5.0;) , __powtmp2 * ...` of type `double` to `int`
        int y = ( x + 5 ) ^^ 2;
                ^
and after:
    ex.d(4): Error: cannot implicitly convert expression `(x + 5.0) ^^ 2L` of type `double` to `int`
        int y = ( x + 5 ) ^^ 2;
                ^

* Update C++ frontend header to match change in `CommaExp`

* Address code review feedback

Co-authored-by: Dennis Korpel <dkorpel@gmail.com>

---------

Co-authored-by: Dennis Korpel <dkorpel@gmail.com>
2025-03-29 12:13:38 +01:00
Nick Treleaven
13b0745e33
Fix error when struct initializer isn't accepted (#21086)
* Fix error when struct initializer isn't accepted

* Rename StructDeclaration.hasRegularCtor parameter to ignoreDisabled

checkDisabled detected disabled ctors when it was false, which was
confusing!

* Update tests
2025-03-26 11:28:07 +01:00
Dennis
3142290b6f
Improve 'no property' error suggestions for pointers (#21087) 2025-03-26 15:43:36 +08:00
Samrendra Pratap Singh
c26b03fba2
Fix dlang#18262 - Fix expected error message for enum auto-increment (#21067)
* Fix dlang#18262 - Resolved special enum case and other conflicts

* Fix dlang#18262 - Resolved Special Enum case and failing test.

* Fix dlang#18262 - Resolved special enum case and other failing tests
2025-03-25 18:25:34 +08:00
Nick Treleaven
e896b5c98d
Fix hidden base constructor supplemental message (#21069)
Fixes #21068.
Also say base class *constructor* in supplemental message.
2025-03-24 05:47:29 +08:00
Dennis
0ae065db22
Fix #20901: can escape stack pointer through indexed array literal (#21063) 2025-03-23 08:35:43 +08:00
Dennis
53024b9fc5
Don't raise "cannot return non-void" on Terror (#21028) 2025-03-23 07:40:57 +08:00
Dennis
7fb4d613af
Use errorSupplemental for long errors with 2 sentences (#21060) 2025-03-23 06:03:20 +08:00
Dennis
31bfe613b0
Require adjacent auto ref return as well (#21061) 2025-03-23 05:59:00 +08:00
Iain Buclaw
02a64d2e13
Fix #21045 - import __stdin causes compilation to pause while reading from stdin (#21047)
Moves the special handling of reading from stdin out of the semantic
routines to the DMD driver itself. All references to `__stdin.d` have
also been removed from the frontend implementation.
2025-03-22 13:00:35 +01:00
Dennis
8a96c4745c
Fix #21054 - No location for array literal sliced from init symbol (#21055) 2025-03-22 16:26:49 +08:00
Dennis
dce0ebac9b
Fix #21052 - Missing @nogc check for enum variable initialization (#21053) 2025-03-22 07:40:34 +08:00
Dennis
d5db322fce
Merge stable (#21048)
* bump VERSION to v2.110.0

* purge changelog

* bump VERSION to v2.111.0-beta.1

* Accept __rvalue attribute on ref functions; which will force the result to be treated as __rvalue. (#20946)

This is essential to implement `move`, `forward`, etc.

* memoryerror.d: Fix AnySupported version condition (#20983)

* Fix #20982 - wrong line number in iasmgcc (#20993)

* Move genCfunc to cxxfrontend (#20992)

* druntime: Fix compilation of rt.cover on Android (#21015)

* Expose SourceLoc to C++ interface (#20980)

* [stable] C++ header fixes for declaration, expression, and typinf (#21016)

Seen either from compilation errors or missing symbols at link time.

* C++ headers: Add 3 Declaration bitfield setters/getters required by LDC

* druntime: Add module declaration to rt.invariant, to prevent conflicts with user-provided invariant.d (#21017)

* Fix #21020 - Indexing a *cast* AA yields no lvalue anymore (#21029)

* Add C++23 to CppStdRevision enum (#21043)

* Improve UFCS/property error message (#21046)

---------

Co-authored-by: Manu Evans <turkeyman@gmail.com>
Co-authored-by: Martin Kinkelin <kinke@users.noreply.github.com>
Co-authored-by: Iain Buclaw <ibuclaw@gdcproject.org>
Co-authored-by: Martin Kinkelin <noone@nowhere.com>
2025-03-21 15:48:21 +01:00
Dennis
9d2f034398
Improve UFCS/property error message (#21046) 2025-03-21 15:15:29 +01:00
Abul Hossain Khan
dafb58bc77
Fix: Prevent ICE on final switch forward referencing its enum (#21001)
* Fix: Prevent ICE on final switch forward referencing its enum

* more simpler approach

* moved the enum member analysis

* Move enum number analysis to sementic2

* WhiteSpace Remove

* Remove Redundant Code in enumsem
2025-03-20 16:43:37 +01:00
Abul Hossain Khan
8663b6dcdc
Fix : Improved error message on override mismatch (#21023) 2025-03-18 08:28:57 +08:00
Paul Backus
7c95446800
Don't parse lambda as UDA without parentheses (#21009)
This brings the compiler's behavior in line with the language spec.

Fixes dlang/dlang.org#4137
2025-03-17 08:31:39 +08:00
Abul Hossain Khan
cf2674f689
Fix #20075 - Improve error message for immutable constructor type mismatch (#20990) 2025-03-16 08:00:27 +08:00
Abul Hossain Khan
6476cebd44
Fix #20318 Compiler should explain why implicit conversion to mutable fails (#20984) 2025-03-14 19:09:40 +08:00
Dennis Korpel
5375db4f76 Merge branch 'stable' into merge-stable 2025-03-05 11:03:30 +01:00
Walter Bright
73158d8a78 add Placement New 2025-03-03 16:23:02 +10:00
Dennis
2c304a4377
Fix #20929 - #line directives mess up -verrors=context (#20930) 2025-02-28 23:47:26 +01:00
Dennis
54a142412c
Improve error for failing opDispatch instantiation (#20902) 2025-02-20 10:40:10 +01:00
Dennis
0e5c41f799
Escape backticks in error messages (#20893) 2025-02-19 07:06:47 +08:00
Dennis
e082ce247a
Expand toErrMsg to other types (#20896) 2025-02-19 06:39:32 +08:00
Elias Batek
f68ca2cbe0
Fix #20888 - Compiler spits out implicit conversion technobabble when a return statement doesn't match the return type of a function (#20890) 2025-02-18 16:55:56 +08:00
Dennis Korpel
b5e0bee399 Fix fail_compilation/retscope TEST_OUTPUT blocks 2025-02-17 23:29:05 +01:00
Dennis Korpel
efd10b140c Print function bodies instead of __lambda in error messages 2025-02-17 00:41:33 +01:00
Dennis Korpel
eb083c06d9 Fix #20859 - ICE: class with __vtbl field name causes segfault in Scope::inCfile 2025-02-16 23:45:36 +01:00
Dennis
961862c455
Deprecate typesafe variadic class arguments (#20673) 2025-02-16 21:35:11 +01:00
Dennis
9f33f031f0
Rephrase "no identifier for declarator" parse error (#20872) 2025-02-16 08:09:43 +08:00
Dennis
4b57724c91
Improve parser errors for statements at global scope (#20871) 2025-02-15 23:50:34 +01:00
Dennis
d29e3eca45
Remove reference to _d_arrayassign in errors (#20808) 2025-01-31 00:08:38 +01:00