Issue 20339 - isPOD returns true if sizeof is accessed inside struct declaration
Summary: isPOD returns true if sizeof is accessed inside struct declaration
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P3 normal
Assignee: No Owner
URL:
Keywords: pull
Depends on:
Blocks:
 
Reported: 2019-10-30 20:17 UTC by Suleyman Sahmi (سليمان السهمي)
Modified: 2023-12-21 22:20 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Suleyman Sahmi (سليمان السهمي) 2019-10-30 20:17:52 UTC
```
struct S
{
    pragma(msg, S.sizeof);

    this(this){}
    ~this(){}

    int f;
}

pragma(msg, __traits(isPOD, S));
```
output:
---
4LU
true
---

expected
---
4LU
false
---

This happening in production code which does more sophisticated things than print sizeof at compile time. I discovered it with `std.uni.Grapheme` from phobos see: https://run.dlang.io/is/Yy8mLt it prints true while the `std.uni.Grapheme` defines the postblit.
Comment 1 Dlang Bot 2019-10-31 13:54:29 UTC
@SSoulaimane updated dlang/dmd pull request #10519 "Fix issue 20339 - recalculate isPOD at the end of semantic analysis" fixing this issue:

- Fix issue 20339 - Defer isPOD and argtypes calculation till the end of semantic analysis
  
  In addition to incorrect results being returned, the ABI is affected with regards to argument passing.

https://github.com/dlang/dmd/pull/10519
Comment 2 Dlang Bot 2023-12-21 12:01:19 UTC
@tim-dlang created dlang/dmd pull request #15939 "Calculate isPOD without information from semantic run" fixing this issue:

- Calculate isPOD without information from semantic run
  
  Fix issue 20339 - isPOD returns true if sizeof is accessed inside struct declaration
  Fix issue 24292 - Struct with destructor wrongly returned in register
  
  Function StructDeclaration.isPOD can be called before the semantic run
  for the struct is finished. It then uses incomplete information about
  destructors, postblits and copy constructors. The result of isPOD is
  cached, so later calls will also return the wrong result.
  
  This commit changes isPOD, so it uses variables, which are already
  filled before the semantic run.

https://github.com/dlang/dmd/pull/15939
Comment 3 Dlang Bot 2023-12-21 22:20:18 UTC
dlang/dmd pull request #15939 "Fixes issues 20339, 24292: Calculate isPOD without information from semantic run" was merged into master:

- 3364291b569ea832091f576d354c6e4d598315ab by Tim Schendekehl:
  Fixes issues 20339, 24292: Calculate isPOD without information from semantic run
  
  Issue 20339: isPOD returns true if sizeof is accessed inside struct declaration
  Issue 24292: Struct with destructor wrongly returned in register
  
  Function StructDeclaration.isPOD can be called before the semantic run
  for the struct is finished. It then uses incomplete information about
  destructors, postblits and copy constructors. The result of isPOD is
  cached, so later calls will also return the wrong result.
  
  This commit changes isPOD, so it uses variables, which are already
  filled before the semantic run.

https://github.com/dlang/dmd/pull/15939