Cannot pass objects of non-trivially-copyable type 'class String' through '...' I'm attempting to send data from a serial connection to a GSM modem, but having problems.
The string from rx looks like this: 

1.0 2.0 3.0 4.0


Here's my code to replace the spaces and then I just want to pass the whole string on, regardless of what's inside (there could be negative values too).

                data_current[data_index++] = ',';
                char received = bike_port.read(); //bike
                char test[32];
                inData += received;     
                  if (received == '\n')
                  {
                      String nospace = inData;
                      nospace.replace("\t",",");
                      debug_println("Data: ");
                      debug_println(nospace);
                      inData = ""; // Clear recieved buffer
                      delay(1000);
                  }  
                  sprintf(test,32,"%d,%d,%d,%d",(String) nospace);
                //strtok(received, tmp);
                for (int i=0; i&lt;strlen(test); i++) {
                  data_current[data_index++] = test[i];
                } 


I have also tried

sprintf(test,32,"%ld,(String) nospace);


What I get now is this error

cannot pass objects of non-trivially-copyable type 'class String' through '...'


Without the sprintf line I can successfully echo the string to debug_println (Serial Monitor). 
What am I doing wrong?
The basic problem here is that you're trying to pass a String object to sprintf(). That isn't possible because String is a C++ class, and sprintf() is a C variadic function. The only way to pass a string to it is as a char *.

The rest of your call to sprintf() doesn't seem to make sense either, although I suspect it's not what you actually want here. You'd normally use sprintf() if you want to format several values into a string.

As you've suggested in the comments, adding the contents of nospace to data_current character-at-a-time would be the sensible approach. You could do it something like this:

for (int i = 0; i &lt; nospace.length(); ++i) {
    data_current[data_index++] = nospace[i];
}


Note that strlen() won't work on nospace because it's a String object not a char array.

This is all assuming that there's enough space in data_current though. Without seeing the rest of your code, I can't tell you if it will definitely work or not.



Update:
As an alternative, you could use memcpy() to do a block transfer:

memcpy(data_current + data_index, nospace.c_str(), nospace.length());
data_index += nospace.length();


I'm not sure there's much benefit to doing that though. It's hypothetically more efficient, but it probably won't make a noticeable difference unless your string is moderately long and it's being called very frequently. (It's trading-off the loop overhead against a function-call overhead.)