<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/110086>110086</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Inconsistent compilation behaviour between windows and ndk clang
</td>
</tr>
<tr>
<th>Labels</th>
<td>
clang
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
sun-xm
</td>
</tr>
</table>
<pre>
Below code can be compiled with windows clang but not ndk clang:
/////////////////////////////////////
typedef struct _AType* AType;
template<typename T>
struct Test
{
T& operator[](size_t index)
{
return this->val[index];
}
// need to comment off below otherwise ambiguous operator[] error is reported in ndk
operator AType() const
{
return this->atype;
}
operator T*()
{
return this->val;
}
AType atype;
T val[10];
};
Test<int> t;
t[0]; // ambiguous operator[] error in ndk
Enviroment:
windows: win10 + vscode 1.93.1 + cmake 3.29.2 + clang 18.1.8
android: win10 + android studio 2024.1.1 Patch 1 + cmake 3.30.3 + ndk 27.1.12297006 (clang 18.0.2)
Error log in ndk:
C:\Users\xxx\AppData\Local\Android\Sdk\ndk\27.1.12297006\toolchains\llvm\prebuilt\windows-x86_64\bin\clang++.exe --target=armv7-none-linux-androideabi24 --sysroot=C:/Users/xxx/AppData/Local/Android/Sdk/ndk/27.1.12297006/toolchains/llvm/prebuilt/windows-x86_64/sysroot -Dopencl_EXPORTS -I.../app/src/main/cpp/../../../../../../../../Modules/OCL/Source -I.../app/src/main/cpp/../../../../../../../../Source/Common -I.../app/src/main/cpp/../../../../../../../../Source/OpenCL.Jni -g -DANDROID -fdata-sections -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -D_FORTIFY_SOURCE=2 -march=armv7-a -mthumb -Wformat -Werror=format-security -std=c++11 -fno-limit-debug-info -fPIC -MD -MT CMakeFiles/opencl.dir/native-lib.cpp.o -MF CMakeFiles\opencl.dir\native-lib.cpp.o.d -o CMakeFiles/opencl.dir/native-lib.cpp.o -c .../app/src/main/cpp/native-lib.cpp
.../app/src/main/cpp/native-lib.cpp:95:6: error: use of overloaded operator '[]' is ambiguous (with operand types 'Test<int>' and 'int')
95 | t[0];
| ~^~
.../app/src/main/cpp/native-lib.cpp:66:8: note: candidate function
66 | T& operator[](size_t index)
| ^
.../app/src/main/cpp/native-lib.cpp:95:6: note: built-in candidate operator[](struct _AType *, int)
95 | t[0];
| ^
.../app/src/main/cpp/native-lib.cpp:95:6: note: built-in candidate operator[](const struct _AType *, int)
.../app/src/main/cpp/native-lib.cpp:95:6: note: built-in candidate operator[](volatile struct _AType *, int)
.../app/src/main/cpp/native-lib.cpp:95:6: note: built-in candidate operator[](const volatile struct _AType *, int)
.../app/src/main/cpp/native-lib.cpp:95:6: note: built-in candidate operator[](int *, int)
.../app/src/main/cpp/native-lib.cpp:95:6: note: built-in candidate operator[](const int *, int)
.../app/src/main/cpp/native-lib.cpp:95:6: note: built-in candidate operator[](volatile int *, int)
.../app/src/main/cpp/native-lib.cpp:95:6: note: built-in candidate operator[](const volatile int *, int)
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzMV01v2zgT_jX0ZUBBpkx_HHywZQvIi-ZNkbro7imgpJHNjUQKJOU4e-hvX1CSHTk9pNmPtkFAyMOZ4fPMkJyhsFbuFeKS8DXhm5Fo3EGbpW0UPVWjVOfPyzWW-gkynSNkQkGKkOmqliXm8CTdAZ6kyvWThawUag9p40BpByp_7CQkWpFwQ8LzyJIf-t8u6p5rzLEA60yTOXhY7Z5rJGwF3Ue0HiJ0WNWlcEii2NspUSHsSLTtZnsXO7SuN5r11gAAO8KmoGs0wmnThZSwuZV_4oMDqXI8EbZ4Ub-y9X8GXWMUuIO0lETboygJX3d2fHPBCWS2GSJuXbV0QSHm4LRPUYXKgS4KSNsEandA8yQtgqhSuW90Y18hBTRGG5AWDNbaOMxBKp_Il1XOBn3g2JywBWRanYNxTeoVG-GGwe5Uv-FxWWFH2Kpb4Dtc-0C94bhFDN9i2EEX5XE4DLF3cL0t2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