This was found when building libvmaf version 3.2.1 on Gentoo with llvm-23.1.2 and clang-23.1.2 (i.e. on an LLVM profile). I reproduced this bug even with master.
A snippet from the build log (a full build log can be found in the downstream bug):
FAILED: [code=1] src/liblibsvm.a.p/svm.cpp.o
clang++ -Isrc/liblibsvm.a.p -Isrc -I../vmaf-3.2.1/libvmaf/src -Iinclude -I../vmaf-3.2.1/libvmaf/include -I../vmaf-3.2.1/libvmaf/src/feature -I../vmaf-3.2.1/libvmaf/src/feature/common -fdiagnostics-color=always -D_LIBCPP_HARDENING_MODE=_LIBCPP_HARDENING_MODE_FAST -D_FILE_OFFSET_BITS=64 -Wall -Winvalid-pch -Wextra -std=c++11 -D_GNU_SOURCE -O2 -pipe -march=native -fPIC -pthread -pedantic -DOC_NEW_STYLE_INCLUDES -U_LIBCPP_ENABLE_ASSERTIONS -MD -MQ src/liblibsvm.a.p/svm.cpp.o -MF src/liblibsvm.a.p/svm.cpp.o.d -o src/liblibsvm.a.p/svm.cpp.o -c ../vmaf-3.2.1/libvmaf/src/svm.cpp
In file included from ../vmaf-3.2.1/libvmaf/src/svm.cpp:13:
In file included from /usr/include/c++/v1/vector:314:
In file included from /usr/include/c++/v1/__vector/vector.h:49:
/usr/include/c++/v1/__split_buffer:195:5: error: call to 'swap' is ambiguous
195 | swap(__begin_, __begin);
| ^~~~
diff --git a/libvmaf/src/svm.cpp b/libvmaf/src/svm.cpp
index 94d3379d80d7..de31e6822557 100644
--- a/libvmaf/src/svm.cpp
+++ b/libvmaf/src/svm.cpp
@@ -21,7 +21,7 @@ template <class T> static inline T min(T x,T y) { return (x<y)?x:y; }
#ifndef max
template <class T> static inline T max(T x,T y) { return (x>y)?x:y; }
#endif
-template <class T> static inline void swap(T& x, T& y) { T t=x; x=y; y=t; }
+template <class T> static inline void custom_swap(T& x, T& y) { T t=x; x=y; y=t; }
template <class S, class T> static inline void clone(T*& dst, S* src, int n)
{
dst = new T[n];
@@ -149,7 +149,7 @@ int Cache::get_data(const int index, Qfloat **data, int len)
// allocate new space
h->data = (Qfloat *)realloc(h->data,sizeof(Qfloat)*len);
size -= more;
- swap(h->len,len);
+ custom_swap(h->len,len);
}
lru_insert(h);
@@ -163,18 +163,18 @@ void Cache::swap_index(int i, int j)
if(head[i].len) lru_delete(&head[i]);
if(head[j].len) lru_delete(&head[j]);
- swap(head[i].data,head[j].data);
- swap(head[i].len,head[j].len);
+ custom_swap(head[i].data,head[j].data);
+ custom_swap(head[i].len,head[j].len);
if(head[i].len) lru_insert(&head[i]);
if(head[j].len) lru_insert(&head[j]);
- if(i>j) swap(i,j);
+ if(i>j) custom_swap(i,j);
for(head_t *h = lru_head.next; h!=&lru_head; h=h->next)
{
if(h->len > i)
{
if(h->len > j)
- swap(h->data[i],h->data[j]);
+ custom_swap(h->data[i],h->data[j]);
else
{
// give up
@@ -214,8 +214,8 @@ public:
virtual double *get_QD() const = 0;
virtual void swap_index(int i, int j) const // no so const...
{
- swap(x[i],x[j]);
- if(x_square) swap(x_square[i],x_square[j]);
+ custom_swap(x[i],x[j]);
+ if(x_square) custom_swap(x_square[i],x_square[j]);
}
protected:
@@ -454,13 +454,13 @@ private:
void Solver::swap_index(int i, int j)
{
Q->swap_index(i,j);
- swap(y[i],y[j]);
- swap(G[i],G[j]);
- swap(alpha_status[i],alpha_status[j]);
- swap(alpha[i],alpha[j]);
- swap(p[i],p[j]);
- swap(active_set[i],active_set[j]);
- swap(G_bar[i],G_bar[j]);
+ custom_swap(y[i],y[j]);
+ custom_swap(G[i],G[j]);
+ custom_swap(alpha_status[i],alpha_status[j]);
+ custom_swap(alpha[i],alpha[j]);
+ custom_swap(p[i],p[j]);
+ custom_swap(active_set[i],active_set[j]);
+ custom_swap(G_bar[i],G_bar[j]);
}
void Solver::reconstruct_gradient()
@@ -1301,8 +1301,8 @@ public:
{
cache->swap_index(i,j);
Kernel::swap_index(i,j);
- swap(y[i],y[j]);
- swap(QD[i],QD[j]);
+ custom_swap(y[i],y[j]);
+ custom_swap(QD[i],QD[j]);
}
~SVC_Q()
@@ -1350,7 +1350,7 @@ public:
{
cache->swap_index(i,j);
Kernel::swap_index(i,j);
- swap(QD[i],QD[j]);
+ custom_swap(QD[i],QD[j]);
}
~ONE_CLASS_Q()
@@ -1390,9 +1390,9 @@ public:
void swap_index(int i, int j) const
{
- swap(sign[i],sign[j]);
- swap(index[i],index[j]);
- swap(QD[i],QD[j]);
+ custom_swap(sign[i],sign[j]);
+ custom_swap(index[i],index[j]);
+ custom_swap(QD[i],QD[j]);
}
Qfloat *get_Q(int i, int len) const
@@ -1908,7 +1908,7 @@ static void svm_binary_svc_probability(
for(i=0;i<prob->l;i++)
{
int j = i+rand()%(prob->l-i);
- swap(perm[i],perm[j]);
+ custom_swap(perm[i],perm[j]);
}
for(i=0;i<nr_fold;i++)
{
@@ -2059,8 +2059,8 @@ static void svm_group_classes(const svm_problem *prob, int *nr_class_ret, int **
//
if (nr_class == 2 && label[0] == -1 && label[1] == 1)
{
- swap(label[0],label[1]);
- swap(count[0],count[1]);
+ custom_swap(label[0],label[1]);
+ custom_swap(count[0],count[1]);
for(i=0;i<l;i++)
{
if(data_label[i] == 0)
@@ -2373,7 +2373,7 @@ void svm_cross_validation(const svm_problem *prob, const svm_parameter *param, i
for(i=0;i<count[c];i++)
{
int j = i+rand()%(count[c]-i);
- swap(index[start[c]+j],index[start[c]+i]);
+ custom_swap(index[start[c]+j],index[start[c]+i]);
}
for(i=0;i<nr_fold;i++)
{
@@ -2410,7 +2410,7 @@ void svm_cross_validation(const svm_problem *prob, const svm_parameter *param, i
for(i=0;i<l;i++)
{
int j = i+rand()%(l-i);
- swap(perm[i],perm[j]);
+ custom_swap(perm[i],perm[j]);
}
for(i=0;i<=nr_fold;i++)
fold_start[i]=i*l/nr_fold;
This was found when building libvmaf version 3.2.1 on Gentoo with llvm-23.1.2 and clang-23.1.2 (i.e. on an LLVM profile). I reproduced this bug even with master.
A snippet from the build log (a full build log can be found in the downstream bug):
I'm guessing this is newer Clang is more stricter in terms of imports and the
swapfunction inlibvmaf/src/svm.cppis conflicting withstd::swap. As a test/workaround I re-named the inlineswapfunction tocustom_swapand it did help in building.Downstream bug: https://bugs.gentoo.org/983392