Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix specialization of
SomeType<N>
when N
is a const parameter.
Fixes #761.
- Loading branch information
1 parent
13b31dd
commit a79a10d
Showing
11 changed files
with
273 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#include <stdarg.h> | ||
#include <stdbool.h> | ||
#include <stdint.h> | ||
#include <stdlib.h> | ||
|
||
typedef struct Inner_1 { | ||
uint8_t bytes[1]; | ||
} Inner_1; | ||
|
||
typedef struct Outer_1 { | ||
struct Inner_1 inner; | ||
} Outer_1; | ||
|
||
typedef struct Inner_2 { | ||
uint8_t bytes[2]; | ||
} Inner_2; | ||
|
||
typedef struct Outer_2 { | ||
struct Inner_2 inner; | ||
} Outer_2; | ||
|
||
struct Outer_1 one(void); | ||
|
||
struct Outer_2 two(void); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#include <stdarg.h> | ||
#include <stdbool.h> | ||
#include <stdint.h> | ||
#include <stdlib.h> | ||
|
||
typedef struct Inner_1 { | ||
uint8_t bytes[1]; | ||
} Inner_1; | ||
|
||
typedef struct Outer_1 { | ||
struct Inner_1 inner; | ||
} Outer_1; | ||
|
||
typedef struct Inner_2 { | ||
uint8_t bytes[2]; | ||
} Inner_2; | ||
|
||
typedef struct Outer_2 { | ||
struct Inner_2 inner; | ||
} Outer_2; | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif // __cplusplus | ||
|
||
struct Outer_1 one(void); | ||
|
||
struct Outer_2 two(void); | ||
|
||
#ifdef __cplusplus | ||
} // extern "C" | ||
#endif // __cplusplus |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#include <stdarg.h> | ||
#include <stdbool.h> | ||
#include <stdint.h> | ||
#include <stdlib.h> | ||
|
||
typedef struct { | ||
uint8_t bytes[1]; | ||
} Inner_1; | ||
|
||
typedef struct { | ||
Inner_1 inner; | ||
} Outer_1; | ||
|
||
typedef struct { | ||
uint8_t bytes[2]; | ||
} Inner_2; | ||
|
||
typedef struct { | ||
Inner_2 inner; | ||
} Outer_2; | ||
|
||
Outer_1 one(void); | ||
|
||
Outer_2 two(void); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#include <stdarg.h> | ||
#include <stdbool.h> | ||
#include <stdint.h> | ||
#include <stdlib.h> | ||
|
||
typedef struct { | ||
uint8_t bytes[1]; | ||
} Inner_1; | ||
|
||
typedef struct { | ||
Inner_1 inner; | ||
} Outer_1; | ||
|
||
typedef struct { | ||
uint8_t bytes[2]; | ||
} Inner_2; | ||
|
||
typedef struct { | ||
Inner_2 inner; | ||
} Outer_2; | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif // __cplusplus | ||
|
||
Outer_1 one(void); | ||
|
||
Outer_2 two(void); | ||
|
||
#ifdef __cplusplus | ||
} // extern "C" | ||
#endif // __cplusplus |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#include <cstdarg> | ||
#include <cstdint> | ||
#include <cstdlib> | ||
#include <ostream> | ||
#include <new> | ||
|
||
template<uintptr_t N> | ||
struct Inner { | ||
uint8_t bytes[N]; | ||
}; | ||
|
||
template<uintptr_t N> | ||
struct Outer { | ||
Inner<N> inner; | ||
}; | ||
|
||
extern "C" { | ||
|
||
Outer<1> one(); | ||
|
||
Outer<2> two(); | ||
|
||
} // extern "C" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
from libc.stdint cimport int8_t, int16_t, int32_t, int64_t, intptr_t | ||
from libc.stdint cimport uint8_t, uint16_t, uint32_t, uint64_t, uintptr_t | ||
cdef extern from *: | ||
ctypedef bint bool | ||
ctypedef struct va_list | ||
|
||
cdef extern from *: | ||
|
||
ctypedef struct Inner_1: | ||
uint8_t bytes[1]; | ||
|
||
ctypedef struct Outer_1: | ||
Inner_1 inner; | ||
|
||
ctypedef struct Inner_2: | ||
uint8_t bytes[2]; | ||
|
||
ctypedef struct Outer_2: | ||
Inner_2 inner; | ||
|
||
Outer_1 one(); | ||
|
||
Outer_2 two(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#include <stdarg.h> | ||
#include <stdbool.h> | ||
#include <stdint.h> | ||
#include <stdlib.h> | ||
|
||
struct Inner_1 { | ||
uint8_t bytes[1]; | ||
}; | ||
|
||
struct Outer_1 { | ||
struct Inner_1 inner; | ||
}; | ||
|
||
struct Inner_2 { | ||
uint8_t bytes[2]; | ||
}; | ||
|
||
struct Outer_2 { | ||
struct Inner_2 inner; | ||
}; | ||
|
||
struct Outer_1 one(void); | ||
|
||
struct Outer_2 two(void); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#include <stdarg.h> | ||
#include <stdbool.h> | ||
#include <stdint.h> | ||
#include <stdlib.h> | ||
|
||
struct Inner_1 { | ||
uint8_t bytes[1]; | ||
}; | ||
|
||
struct Outer_1 { | ||
struct Inner_1 inner; | ||
}; | ||
|
||
struct Inner_2 { | ||
uint8_t bytes[2]; | ||
}; | ||
|
||
struct Outer_2 { | ||
struct Inner_2 inner; | ||
}; | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif // __cplusplus | ||
|
||
struct Outer_1 one(void); | ||
|
||
struct Outer_2 two(void); | ||
|
||
#ifdef __cplusplus | ||
} // extern "C" | ||
#endif // __cplusplus |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
from libc.stdint cimport int8_t, int16_t, int32_t, int64_t, intptr_t | ||
from libc.stdint cimport uint8_t, uint16_t, uint32_t, uint64_t, uintptr_t | ||
cdef extern from *: | ||
ctypedef bint bool | ||
ctypedef struct va_list | ||
|
||
cdef extern from *: | ||
|
||
cdef struct Inner_1: | ||
uint8_t bytes[1]; | ||
|
||
cdef struct Outer_1: | ||
Inner_1 inner; | ||
|
||
cdef struct Inner_2: | ||
uint8_t bytes[2]; | ||
|
||
cdef struct Outer_2: | ||
Inner_2 inner; | ||
|
||
Outer_1 one(); | ||
|
||
Outer_2 two(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// Propagating const arguments through generics that use generics. | ||
|
||
#[repr(C)] | ||
pub struct Inner<const N: usize> { | ||
pub bytes: [u8; N], | ||
} | ||
|
||
#[repr(C)] | ||
pub struct Outer<const N: usize> { | ||
pub inner: Inner<N>, // don't declare two different structs named `Inner_N` | ||
} | ||
|
||
#[no_mangle] | ||
pub extern "C" fn one() -> Outer<1> { | ||
Outer { inner: Inner { bytes: [0] } } | ||
} | ||
|
||
#[no_mangle] | ||
pub extern "C" fn two() -> Outer<2> { | ||
Outer { inner: Inner { bytes: [0, 0] } } | ||
} | ||
|